Wednesday 13 July 2016

[Visual Studio] Creating Web Performance Test for Load Test [Part 1]

Ever thought of how well your web application performed when it is being put to stress test, or how much requests can your web application processed them, or how quick your web application respond to each request when under load. If you have Visual Studio Ultimate Edition (2013 and older) or Visual Studio Enterprise Edition (2015), there is a project called "Web Performance and Load Test Project" specially for Ultimate and Enterprise Edition only. For more details about the comparison between Visual Studio 2015 edition, check them out here https://www.visualstudio.com/en-us/products/compare-visual-studio-2015-products-vs.aspx.

Before creating the project, make sure you have a running web application that are deployed to your IIS or any test machine. It is strongly discourage and make sure not to run the test to your web application that is hosted on your production / live server as it will use up of your network bandwidth and slowdown your web application due to the huge number of requests sent by the load test project need to be processed.

Steps to create a "Web Performance and Load Test Project".
1) On your solution in Visual Studio, right click on it, hover to "Add" and click "New Project...". A window named "Add New Item" will be prompted.
Add New Project
Add New Project
2) On the left pane, expand "Installed" and expand ["Visual C#" for C# or "Visual Basic" for VB], click "Test". Just in case Test is not appearing, look for the search bar located at top right corner, type "Web Performance and Load Test Project" and hit enter key.

3) On middle pane, select "Web Performance and Load Test Project". Fill in your desired name and location. Once you are done. Click "OK" button.
Add New Web Performance and Load Test Project
Add New Web Performance and Load Test Project
Once the project is created, you will notice there is a file called "WebTest1.webtest". This is the Web Performance Test file. Again, just in case this file does not appear, you can follow the following steps to create it. Otherwise just skip these steps.

Steps to add a "Web Performance Test" file.
1) On your Solution Explorer in Visual Studio, right click on the "Web Performance and Load Test Project" that you have created earlier. Hover to "Add" and click "New Item...".
Add New Item
Add New Item
2) On the left pane, expand "Installed" and expand further until you see "Test". Click on it. In case you can't find it. Look for search bar at top right corner, type "Web Performance Test" and hit enter key.

3) On middle pane, select "Web Performance Test". Fill in your desired name and location. Once you are done. Click "OK" button.
Add New Web Performance Test
Add New Web Performance Test
4) Once the file created, it will automatically launch IE with recording. You can just cancel it.

There are a few ways to setup the Web Performance Test file to test your web pages or services.

[Option 1] - Manually fill in your services detail.
Scenario: Assume that you want to make a service call to WCF service that contain parameter and return something back.
1) Open up your Web Performance Test, right click on that "TestCaseUI" and click Add Web Service Request.
Add Web Service Request
Add Web Service Request
2) Right click on the newly created "Web Service Request" and click properties. Look for Url and change it to your desired URL. In this demo, assuming the following are my Web Service URL. http://localhost/WPTDemo/RedemptionService.svc
Web Service Request - Properties
Web Service Request - Properties
Properties - Url
Properties - Url
2) Right click on the newly created "Web Service Request" and click "Add Header".
Web Service Request - Properties
Web Service Request - Properties
3) Expand the headers folder and right click on that only node in the headers folder and click "properties".
Headers - Properties
Headers - Properties
4) Set the Name field as "SOAPAction". Set the Value field based on your web service action name. The SOAPAction value can be obtained from your web service's wsdl. In this demo, assuming the following are my SOAPAction. http://tempuri.org/IRedemptionService/VerifyUser.
Properties - Name & Value
Properties - Name & Value
5) Right click on String Body and click properties.
String Body - Properties
6) Set "text/xml" to Content Type. Set the request content in XML into the String Body. In this demo, assuming the following are my content.

[Request Body]
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header/>
  <s:Body>
    <VerifyUser xmlns="http://tempuri.org/">
      <name>"John"</name>
    </VerifyUser>
  </s:Body>
</s:Envelope>
Properties - Content Type & String Body
[Option 2] - Use recording (Only Get Method for services)
Scenario: Assume that you want to make a REST service call to WEB API with GET Method.
1) Open up the Web Performance Test and click Add Recording button or create a new Web Performance Test file to start recording. An internet explorer browser will be launched.
Add Recording
Add Recording
2) On the browser, paste your desired URL. In this demo, assuming the following are my WEB API service url. http://localhost/WPTDemo/api/Redemption/John. Once you are done. Click the Stop button and the browser will be automatically closed.
Record Calling Web API Service
Record Calling Web API Service
Note: In case your recording is not working, make sure that the following internet explorer browser's add-ons are enabled.
  • Microsoft Web Test Recorder
  • Web Test Recorder
3) You can remove the unnecessary entries added to your recording.
Recorded
Recorded
Once you have done setting up the Web Performance Test, click the Run Test button to test your service call. Make sure that it is successful and fix it if the test failed.
Run Test
Run Test
Test Result
Test Result
With the Web Performance Test configured, it is now time for load testing. Head over to the following link for the second part of this post. http://jaryl-lan.blogspot.com/2016/07/visual-studio-load-testing-web.html

Refer to the following link for the sample project.
https://1drv.ms/u/s!Aj2AA7hoIWHmgnSNDD55and-C7Ge




No comments:

Post a Comment