How to: Use the load test API
Applies to: Visual Studio Visual Studio for Mac
Note
This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here
Visual Studio supports load test plug-ins which can control or enhance a load test. Load test plug-ins are user defined classes which implement the ILoadTestPlugin interface found in the Microsoft.VisualStudio.TestTools.LoadTesting namespace. Load test plug-ins allow for custom load test control, such as, aborting a load test when a counter or error threshold is met. Use the properties on the LoadTest class to get or set load test parameters from user defined code. Use the events on the LoadTest class to attach delegates for notifications when the load test is running.
Note
Web performance and load test functionality is deprecated. Visual Studio 2019 is the last version where web performance and load testing will be fully available. For more information, see the Cloud-based load testing service end of life blog post. To reduce the impact on users some minimum support is still available in Visual Studio 2022 Preview 3 or later. Users should also note web performance and load test functionality only supports Internet Explorer which is not available on Windows 11 and some versions of Windows 10. Read more on Internet Explorer Lifecycle policy.
Tip
Use the object browser to examine the Microsoft.VisualStudio.TestTools.LoadTesting namespace. Both the Visual C# and Visual Basic editors offer IntelliSense support for coding with the classes in the namespace.
You can also create plug-ins for web performance tests. For more information, see How to: Create a web performance test plug-in and How to: Create a request-level plug-in.
To use the LoadTesting namespace
Open a web performance and load test project that contains a load test.
Add a Visual C# or a Visual Basic class library project to your test solution.
Add a reference in the web performance and load test project to the class library project.
Add a reference to the Microsoft.VisualStudio.QualityTools.LoadTestFramework DLL in the Class Library project.
In the class file located in the class library project, add a
using
statement for the Microsoft.VisualStudio.TestTools.LoadTesting namespace.Create a public class that implements the ILoadTestPlugin interface.
Build the project.
Add the new load test plug-in using the Load Test Editor:
Right-click the root node of the load test and then choose Add Load Test Plug-in.
The Add Load Test Plug-in dialog box is displayed.
In the Properties for selected plug-in pane, set the initial values for the plug-in to use at run time.
Note
You can expose as many properties as you want from your plug-ins. Just make them public, settable, and of a base type such as Integer, Boolean, or String. You can also edit the load test plug-in properties later using the Properties window.
Run your Load test.
For an implementation of ILoadTestPlugin, see How to: Create a load test plug-in.