You might already be familiar with this article. It will tell you how to access your results from code so that you can do whatever you like with them (tweet them, use them to build up a custom dashboard, post them on Facebook etc.). But that's just for functional test.

What about  Performance testing? Can you access your Performance data from a coded snippet? 

Yes, you can.

It's slightly more complex. Performance results are not available immediately after a test has finished running. Hench you won't be able to access them from the OnAfterTestCompleted (reference). Instead you have to access them if you override the OnAfterTestListCompleted function. As the name suggests: Test Studio goes into that function once it has finished executing a TestList.

So the first thing you need to do is prepare your test and put it in a TestList. Set the TestList to Performance:

 

Once you have that it's time to overrride OnAfterTestListCompleted. The tricky part is that OnAfterTestListCompleted is not exposed publicly. You can only override it through a custom Test Studio plug-in. But that's not difficult to put together and we have this article that will walk you through it.

Here's a little example of what your OnAfterTestListCompleted function might look like:

 

public void OnAfterTestListCompleted(RunResult result)
        {
            TraceInfo.Performance.WriteLine("TEST EXTENSION ENDED!!!!!!!!!!!!!!!!!");
            foreach (var testResult in result.TestResults)
            {
                if (testResult.ProfilerResultsPath != "")
                {
                    TraceInfo.Performance.WriteLine("TEST EXTENSION PERF FILE: " + testResult.ProfilerResultsPath);
                    ProfilerResultsFile resultsFile = ProfilerResultsFile.Load(null, testResult.ProfilerResultsPath);

                    StreamWriter sw = File.CreateText("c:\\pRes.txt");

                    foreach (ProfilerTestStep step in resultsFile.Steps)
                    {

                        sw.WriteLine("EXTENSION PERF STEP:");
                        sw.WriteLine(step._serverTime.ToString());
                        sw.WriteLine(step._clientTime.ToString());

                    }

                    sw.Close();
                }
            }
        }

 This code will write your Perf results to a file "c:\\pRes.txt" and you can access them after the TestList is done running.


Related Posts

Comments

Comments are disabled in preview mode.