Pages

Tuesday, December 31, 2013

TestContext.BeginTimer() not writing to test output in VS2013


I am running Visual Studio 2013 Ultimate and can't get TestContext.BeginTimer("TimerName"); and TestContext.EndTimer("TimerName"); to write to the Output window of a CodedUI Test.

This post has a good solution to the issue.

I want to log the duration for groups of test steps.

First I tried writing a logger class and sending the duration to a text file.

This way seems easier to me:

1. Open the Coded UI Test .cs file and add a using statement for System.Diagnostics;


2. Create new instance of Stopwatch and give it some name (Timer in the example), add Timer.Start(); and Timer.Stop(); statements around actions that you're logging duration of, then add statement to write to test output TestContext.WriteLine("Description: " + SomeName.Elapsed.ToString());


3. Reset the timer next time and you can reuse it:


4. Run the test from Test Explorer, select the CodedUITestMethod in the upper pane under Passed Tests, and then click the Output link in the lower portion to view duration.

5. The output window will also show debug trace messages if EqtTraceLevel is set to 4 in QTAgent32.exe.config. TestContext messages are below the Debug Trace messages.