Share →
Buffer

I was recently doing a workshop on Web Performance and Load Testing in Visual Studio when we stumbled upon a testing scenario that required an input of unique invoice identifiers. Essentially, the business logic would fail to create an invoice if the identifier matched one that already existed. This seems like a trivial problem, but when one could be running potentially thousands of invoice requests during load testing, a random integer seems like a solution that would cause a lot of collisions – in turn failing the web performance test. Because of this, we needed to create a plugin that would require a unique (unique-enough) alphanumeric string to be used as the invoice identifier. There is an out-of-box Guid generator, but the max invoice identifier length was 20 characters instead of 32. This required a little bit of string manipulation to be used.

There are a lot of great resources on how to create web performance test plugins, and it is surprisingly trivial to build these plugins. Here’s a couple of resources I found to be useful when creating the web test plugin for my customer:

That being said, this is how I created my own custom web performance test plugin and used it in a test.

Create the plugin

The first thing that we need to do is create the plugin itself. This requires a little bit of coding to be done. We will need to create a new public class either in the web performance and load testing project itself, or another project within the solution. In this example, I created the class within the same project as my web performance test. Here is the code I used:

  1. Create a class and make sure it is public
  2. Add a reference to Microsoft.VisualStudio.TestTools.WebTesting and put a using statement in for it.
  3. Derive the class from WebTestPlugin.
  4. Add any context parameters that you want to expose to the user
  5. Override the PreWebTest method to run your code prior to every web performance test run

It truly is as simple as that. There are other classes you can derive from for specific purposes, but the WebTestPlugin will work just fine for our purposes. Once the class has been created, make sure that you build your solution so it will appear in the plugin list for web performance tests.

NOTE: If you have created this plugin in a different project, ensure that your web performance and load testing project has a reference to that project.

Add plugin to web performance test

Once the plugin has been created, and the solution has been built, we can add the custom plugin to a web performance test for use. The first thing we will want to do is create a context parameter that we want to set as the unique identifier.

AddContextParameter

Figure 1: Add Context Parameter in a web performance test

Right-click on the web test and select the Add Context Parameter. This will add a context parameter to the web test which we can set dynamically using the custom plugin we just wrote. After the parameter has been created, we can rename it to an appropriate label. There is no need to set it to any values, as we will set it through the custom plugin. I named mine InvoiceId:

InvoiceId

Figure 2: InvoiceId context parameter

Now, all we have to do is add the custom plugin and set the correct properties for our plugin. To do so, click the button at the top of the web performance test itself called Add Web Test Plug-in:

AddWebTestPlugin

Figure 3: Add Web Test Plug-in button

This will bring up the dialog to add a web test plugin. If all goes according to plan, we should be able to see our custom plugin in the list. Select the custom plugin and set the appropriate properties:

SetWebTestParameters

Figure 4: Set the plugin, set the plugin properties, and click OK

After setting the properties click OK, and the plugin will be added to your web performance test. I have set the following properties:

  • Target Context Parameter Name = InvoiceId : InvoiceId is the name of the context parameter we want to set the unique identifier to.
  • Output Format = N : N is the guid without any hyphens in it. Here’s a link defining the possible guid formats: http://msdn.microsoft.com/en-us/library/97af8hh4.aspx
  • Guid Length = 12 : This is the length of the string that I want.

Once all is said and done, we should have a web performance test that looks along the lines of this:

WebTestWithCustomPlugin

Figure 5: Web test with a custom plugin and context parameter

Now, whenever the web performance test is run – whether it be by itself, or during a load test – a guid will be generated and the first 12 digits will be set as the InvoiceId.

For further reading on how to create, and run, load tests see my previous blog post: Web Performance and Load Testing with Visual Studio 2012 – Remote Execution.

 

Print Friendly
Tagged with →  
  • Kunal Raje

    Hi James,

    Can you please guide me for
    installation and configuring Controllers and Agents for Web Performance and
    Load test using VSTS 2013 Ultimate? Also, Kindly let me know Is there a
    need for separate machines for Controllers and Agents OR one machine will do the
    same test? I need to perform these tests for our internal Share Point
    application.

    Thanks and Regards,

    Kunal Raje

  • Ian Hodgetts

    Excellent instructions. I’ve been struggling with something very similar for weeks. I’m new to both VS2013 and C# so this helped a great deal!

  • James Tupper

    Glad it helped you out! 🙂

  • James Tupper

    Hi Kunal – I actually have another blog post that covers this particular subject: http://blog.nwcadence.com/web-performance-and-load-testing-with-visual-studio-2012-remote-execution-2/

    Let me know if you have any further questions!

  • Jason Eales

    Hi James
    Good Post!
    I have an issue creating a property inside a WebRequestPlugin.
    The property should provide a dropdown list box with choices the performance developer can make .
    i.e. source.Browser, source.Mobile, source.CourierPigeon
    Browser = “someawesomecode”;
    Mobile = “wickedtextsecret”
    CourierPigeon = “Seeds”
    The developer sees a property called “Source” with a dropdown box and the options displayed in the dropdown box are Browser, Mobile and CourierPigeon.

  • Bipin Kumar

    Hi,

    I am getting below error after adding Web Test Plugin in Web Test.

    Request failed: Exception in PreWebTest event: Could not load file or assembly ‘Project Name, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’ or one of its dependencies. The system cannot find the file specified.

    We have created the Plugin in same solution file.

    Please help.