VS2010 Load Testing: How can I perform custom action that is run once prior to each load test

核能气质少年 提交于 2019-11-27 08:16:47

问题


Basically, I need to restart particular service prior to each load test being run and there is no problem with the restart itself. I've researched for a while and haven't found a way to put some action or script or just another load test, so that I can be sure it is performed before each load test and only one time per load test.

Any ideas regarding how to make it behave this way are appreciated.


回答1:


Create a LoadTest Plugin and use the LoadTestStarting event to call a method that restarts your service.

public class Plugin : ILoadTestPlugin
{
    private LoadTest _loadTest;

    public void Initialize(LoadTest loadTest)
    {
        _loadTest = loadTest;
        _loadTest.LoadTestStarting += new System.EventHandler(loadTest_LoadTestStarting);
        _loadTest.LoadTestFinished += new System.EventHandler(loadTest_LoadTestFinished);
    }

    void loadTest_LoadTestStarting(object sender, System.EventArgs e)
    {
        // Restart your service
    }

    void loadTest_LoadTestFinished(object sender, System.EventArgs e)
    {
    }
}

Then in the Load Test Editor right click on the root and select Add Load Test Plug-in... to add the Plug-In to your Load Test.




回答2:


Another option, especially if you are calling something on the command-line anyway, is to specify a Setup script in the active TestSettings:



来源:https://stackoverflow.com/questions/9990917/vs2010-load-testing-how-can-i-perform-custom-action-that-is-run-once-prior-to-e

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!