VS 2010负载测试结果与自定义计数器 [英] VS 2010 Load Tests Results with custom counters

查看:232
本文介绍了VS 2010负载测试结果与自定义计数器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与Visual Studio 2010和我处理的几个问题负载测试(在一般情况下,测试)新的。

I am new on Load Testing (and in general, testing) with visual studio 2010 and I am dealing with several problems.

我的问题是,是否有任何?可能的方式,添加自定义的测试变量的负载测试结果

My question is, is there any way possible, to add a custom test variable on the Load Test Results?

我有以下的UnitTest:

I have the following UnitTest:

[TestMethod]
public void Test()
{
    Stopwatch testTimer = new Stopwatch();
    testTimer.Start();
    httpClient.SendRequest();
    testTimer.Stop();

    double requestDelay = testTimer.Elapsed.TotalSeconds;
}

这的UnitTest被许多LoadTests,我想添加的 requestDelay 的变量负载测试结果,所以我可以得到最小,最大和平均值的所有其他人一样负载测试仪表(如测试响应时间)。

This UnitTest is used by many LoadTests and I want to add the requestDelay variable to the Load Test Result so I can get Min, Max and Avg values like all others Load Test Counters (e.g. Test Response Time).

时这可能吗?

推荐答案

使用从@Pritam Karmakar评论的链接和演练在帖子的最后,我终于成功地找到一个解决方案。

Using the link from the @Pritam Karmakar comment and the walkthroughs at the end of my post I finally managed to find a solution.

首先,我创建了一个的负载测试插件并使用的 LoadTestStarting事件,以创建我的自定义计数器类别,并给它添加我的所有计数器:

First I created a Load Test Plug-In and used the LoadTestStarting Event to create my Custom Counter Category and add to it all my counters:

void m_loadTest_LoadTestStarting(object sender, System.EventArgs e)
{        
    // Delete the category if already exists   
    if (PerformanceCounterCategory.Exists("CustomCounterSet"))
    {
        PerformanceCounterCategory.Delete("CustomCounterSet");
    }

    //Create the Counters collection and add my custom counters 
    CounterCreationDataCollection counters = new CounterCreationDataCollection();
    counters.Add(new CounterCreationData(Counters.RequestDelayTime.ToString(), "Keeps the actual request delay time", PerformanceCounterType.AverageCount64));
    // .... Add the rest counters

    // Create the custom counter category
    PerformanceCounterCategory.Create("CustomCounterSet", "Custom Performance Counters", PerformanceCounterCategoryType.MultiInstance, counters);
}



然后,在 LoadTest 主编的代理CounterSet 和选定的添加计数器我右键单击... 的在选择性能计数器的窗口我选择了我的表演类,并添加计数器,我向CounterSet所以负载测试将收集他们的数据:

Then, in the LoadTest editor I right-clicked on the Agent CounterSet and selected Add Counters... In the Pick Performance Counters window I chose my performance category and add my counters to the CounterSet so the Load Test will gather their data:

最后,每一个的UnitTest会在 ClassInitialize计数器实例方法,然后在适当的步更新计数器:

Finally, every UnitTest creates instances of the Counters in the ClassInitialize method and then it updates the counters at the proper step:

[TestClass]
public class UnitTest1
{
    PerformanceCounter RequestDelayTime;

    [ClassInitialize]
    public static void ClassInitialize(TestContext TestContext)
    {
        // Create the instances of the counters for the current test
        RequestDelaytime = new PerformanceCounter("CustomCounterSet", "RequestDelayTime", "UnitTest1", false));
        // .... Add the rest counters instances
    }

    [TestCleanup]
    public void CleanUp()
    {
        RequestDelayTime.RawValue = 0;
        RequestDelayTime.EndInit();
        RequestDelayTime.RemoveInstance();
        RequestDelayTime.Dispose();
    }

    [TestMethod]
    public void TestMethod1()
    {
         // ... Testing
         // update counters
         RequestDelayTime.Incerement(time);
         // ... Continue Testing
    }
}



链接:

Links:

  • Creating Performance Counters Programmatically
  • Setting Performance Counters
  • Including unit test variable values in load test results

这篇关于VS 2010负载测试结果与自定义计数器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆