Part-12: Create Sample Load Test Plug-ins–Performance Test in VS 2017
Load Test Plug-ins can be developed to expand or modify the Load Test built in functionality. Load Test allows to add Plug-ins and these Plug-in executes at the time of Load Test run based on specified Events.
To create Load Test Plug-ins, must create a class that inherits the ILoadTestPlugin interface. This class must implement the Initialize method of this interface. Below are the to create Load Test Plug-ins and Add them to Load Tests.
Below sample sends an Email once Load test finishes.
a. Open the test project that contains your load test.
b. Add a new class file
c. Add a using statement for
using Microsoft.VisualStudio.TestTools.LoadTesting;
d. Have the class implement the ILoadTestPlugin interface.
public class NotifyOnLoadTestCompletion : ILoadTestPlugin
e. There is one method in the interface that you must implement:
public void Initialize (Load Test)
PFB for the complete Load Test Plug-in (Taken reference from Microsoft MSDN Article)
using System;
using Microsoft.VisualStudio.TestTools.LoadTesting;
using System.Net.Mail;
using System.Windows.Forms;
namespace SampleLoadTestPlugin
{
public class NotifyOnLoadTestCompletion : ILoadTestPlugin
{
LoadTest myLoadTest;
public void Initialize(LoadTest loadTest)
{
myLoadTest = loadTest;
myLoadTest.LoadTestFinished += new
EventHandler(myLoadTest_LoadTestFinished);
}
void myLoadTest_LoadTestFinished(object sender, EventArgs e)
{
try
{
// place custom code here
MailAddress MyAddress = new MailAddress(“someone@example.com”);
MailMessage MyMail = new MailMessage(MyAddress, MyAddress);
MyMail.Subject = “Load Test Finished — Admin Email”;
MyMail.Body = myLoadTest..Name + ” has finished.”;
SmtpClient MySmtpClient = new SmtpClient(“localhost”);
MySmtpClient.Send(MyMail);
}
catch (SmtpException ex)
{
}
}
}
}
Please refer below references for Load Test Plug-in samples and List of events those supported in Load Test Plug-ins.
This was originally posted here.
*This post is locked for comments