Baran Topal

Baran Topal


September 2022
M T W T F S S
« Feb    
 1234
567891011
12131415161718
19202122232425
2627282930  

Categories


Unit Test and Load Test in VS2010

baranbaran

While I was digging my old backups, I found this article and I am putting as it is. I couldn’t find the author and if the authoer contacts me, I will give his/her credits.

Visual Studio .NET 2010 Unit Testing

Visual Studio provides a template for creating unit test projects.  The projects can have the following types of tests:

Basic

C#, or Visual Basic source code.

A unit test calls the methods of a class, passes suitable parameters, and verifies that the returned value is what you expect.  You can code unit tests by hand.

Coded UI

Use a coded UI test to verify the functionality of the user interface of  your application ﴾Web/Windows  Forms/Windows Presentation  Foundation﴿.  After you create a test, you can record  user actions and generate code from  these actions, or you can use an  action recording to generate a coded UI test.  You can add assertions  using the UI Control Locator.

Database

Use a database unit test to exercise database objects.  You can use a database unit test to test stored procedures, functions, triggers, and any other type of database object.

Generic

A generic test is an existing program that has been wrapped to function as a test in Visual Studio

Load

Use a load test to aggregate tests, and run them simultaneously under simulated load, using virtual users.  For example, load tests let you test the performance of a Web application under peak usage, before you deploy it.

Ordered

Use an ordered test to execute a set of existing tests in a specific order.

Unit

Select methods from an assembly, to automatically create unit tests for.

Web Performance

Use a web performance test within a load test to test the web site performance.

Creating a Unit Test Project

To create a unit test project, right-click on the solution in the Solution Explorer, and select Add | New Project | <Language> | Test | Test Project (where <Language> is the development language – C#, VB.NET, etc.)

Figure 1.  Create new unit test project

Load Tests

The Load Test wizard helps you to generate scenarios to simulate application usage.  You need to have other tests defined in the unit test project, before you can use the Load Test.  Using the wizard, you select which tests you would like to run, scenario settings (i.e. load pattern, test mix, network mix, and browser mix), performance counter settings, and run settings.  You can add a load test to an existing unit test project by right-clicking on the project in the Solution Explorer, and selecting the Add | Load Test… menu.

Figure 2.  Scenario settings.

Figure 3.  Scenario settings.

The first step in the wizard is to name the load test scenario and define the “think time” settings.  The think time is used to simulate real user actions, where there is a pause to think about the next action.  There are multiple options for the think time:  recorded, normally-distributed recorded, and none.  Also, you can define the think time between each test iteration.

Figure 4.  Test Mix Model

The next step is to set the way that you want to model the test mix (total tests, total users, user pace, or sequential).  The following descriptions explain the 4 test mix model options:

Based on the total number of tests:

Determines which Web performance or unit test is run when a virtual user starts a test iteration. At the end of the load test, the number of times that a particular test run matched the assigned test distribution. Use this test mix model when you are basing the test mix on transaction percentages in an IIS log or in production data.

For each test in the mix, you can specify a percentage that determines how frequently the test is selected as the next test to run. For example, you might assign the following percentage values to three tests:

If you use this setting, the next test to start is based on the assigned percentages. You do this without taking into account the number of virtual users who are currently running each test.

Based on the number of virtual users:

Determines the percentage of virtual users who will run a particular Web performance or unit test. At any point in the load test, the number of users who are running a particular test matches the assigned distribution. Use this test mix model when you are basing the test mix on the percentage of users who are running a particular test.

This model of test mix determines the percentage of virtual users who will run a particular test. If you use this model of test mix, the next test to start is based not only on the assigned percentages but also on the percentage of virtual users who are currently running a particular test. At any point in the load test, the number of users who are running a particular test matches the assigned distribution as closely as possible.

Based on user pace:

Over the course of the load test, each Web performance test or unit test is run a specified number of times per users, per hour. Use this test mix model when you want virtual users to run test at a certain pace throughout the load test.

If you specify a pacing test mix, you set a rate of test execution for each virtual user for each test in the test mix. For each test, this rate is expressed as tests run per virtual user per hour. For example, you might assign the following pacing test mix to the following tests:

If you use the pacing test mix model, the load test runtime engine guarantees that the actual rate at which tests are started is less than or equal to the specified rate. If the tests run too long for the assigned number to be completed, an error is returned.

NOTE:  The Think Time Between Test Iterations setting does not apply when you use a pacing test mix.

Based on sequential order:

Each virtual user runs the Web performance or unit tests in the order that the tests are defined in the scenario. The virtual user continues cycling through the tests in this order until the load test is complete.

Selecting the Based on sequential test order option makes each virtual user run all the tests in the scenario in the order that the tests were defined.

Figure 5.  Test Mix

Once you determine which model to use for the test mix, you then need to select which tests that you would like to include, and the weighted distribution % for each test.  When you click the <Add> button, the wizard will look in the unit test project for tests marked with the [TestMethod] attribute.

Example:

[TestMethod]

public void TestMethod()

{

}

Figure 6.  Network Mix

The next step in the wizard is to select the network mix, and the weighted distribution percentage for each network type.  The Network Type drop-down shows popular network types.  For example, you can use the network mix, if your environment has LAN, WAN, and 3G legs.  If you only have a single LAN network, then you may skip this step.

Figure 7.  Browser Mix

The next option available in the wizard is to select a browser mix for web site application testing, and the weighted distribution percentage for each browser instance.  The Browser Type drop-down lists different browser options.  If you have the luxury of a single-browser environment, then you may skip this step.

Figure 8.  Computer and Counter Sets to Monitor

The next section provides options for performance monitoring, and the different counter sets used to monitor the performance.  It is important that you add the servers under test to the list of computers on which to collect counters. Then, any important system data is collected and monitored during the load test.  The load test tools collect and graph performance data by using counters over time. Counter data is collected at user-specified intervals during a load test run.  You can view the counters at run time or you can view them after a load test run by using the Load Test Analyzer.

Counter data is gathered on the server, and on any computer where a test is run. If you have set up a set of agent computers on which to run your tests, counters are gathered on those computers also.  There are three counter categories: percentages, counts, and averages.  Some examples are % CPU usage, SQL Server lock counts, and IIS requests per second.  Performance data for individual HTTP requests is reported by the computer that runs a test. such as an agent computer. For requests, you might monitor data such as Average Time to First Byte, Response Time, and Requests per Second.

To ease collection of performance data on a Web server, Visual Studio Ultimate also provides predefined, named counter sets, based on technology for use in load tests.  These sets are useful when you are analyzing a server that is running IIS, ASP.NET, or SQL Server.  Counters not provided in the default set of counter can be added by using the Load Test Editor. It is important that you add the computers or servers under test to your load test to make sure that you can monitor resource use on these computers.  Results analysis of load runs frequently requires domain-specific knowledge of a particular area in order to know what data to gather, where to set threshold rules, and how to tell when a measurement reflects a specific problem in the application.

References:

Emulating Expected Real-World Usage of a Web Site or Application in a Load Test Using a Test Mix Models

http://msdn.microsoft.com/en-us/library/bb514186.aspx

Specifying the Counter Sets for Computers in a Load Test

http://msdn.microsoft.com/en-us/library/ms404695.aspx