VS 2010 Load Tests Results with custom counters

前端 未结 3 678
不思量自难忘°
不思量自难忘° 2020-12-19 16:34

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

相关标签:
3条回答
  • 2020-12-19 17:20

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

    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);
    }
    

    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:

    enter image description here

    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
    0 讨论(0)
  • 2020-12-19 17:23

    Interesting question. Never tried this, but I have an idea.

    Create 3 class level properties of MAX, MIN and AVG. during each test manipulate those values. And then write all final values once entire load test get executed via Classcleanup or assemblycleanup test attribute. You have to run the load test for 1-2 min and have to see which attribute method get called at the end. You can then print those final values in a flat file in local drive via textwriter.

    0 讨论(0)
  • 2020-12-19 17:27

    I think what you actually need is to use:

    [TestMethod]
    public void Test()
    {
        TestContext.BeginTimer("mytimer");
        httpClient.SendRequest();
        TestContext.EndTimer("mytimer");
    }
    

    You can find good documentation here.

    0 讨论(0)
提交回复
热议问题