locked
TestContext Begin and End Timers are not outputting info to Results.trx RRS feed

  • Question

  • Ok here is some code that I tried to run just to see how the TestContext's BeingTimer and EndTimer worked but has not resulted as expected:

    Snippet

        [TestMethod]
            public void CodedUITestMethod1()
            {
                int tests = 5;
                for (int i = 1; i <= tests; i++)
                {
                    string TestName = "iteration" + i;
                    TestContext.BeginTimer(TestName);
                    Playback.Wait(1000);
                    TestContext.EndTimer(TestName);
                    TestContext.WriteLine("TestCompleted for Test: " + i);
                }

            }

    For some strange reason all i get in the results file is as follows with no output for the timer. Is there a reason why this may have happened? I have also tried this around a test that actually does some UI actions and it still does not output anything. When running with actual UI actions the Debug Trace was not happen like the snippet output below

    Common Results

    Test Run:         UserName@MachineName 2010-06-30 10:54:56
    TestName:       CodedUITestMethod1
    Results:           Passed
    Duration:         00:00:06.0029280
    Computer Name: MachineName
    Start Date: 30/06/2010 10:54:57
    End Date: 30/06/2010 10:55:04

     

    Additional Information

    TestCompleted for Test: 1
    TestCompleted for Test: 2
    TestCompleted for Test: 3
    TestCompleted for Test: 4
    TestCompleted for Test: 5

    Debug Trace

    W, 6096, 13, 2010/06/30, 10:55:04.411, 2449291468243, QTAgent32.exe, IEDOM : StopSession of the plugin called before StartSession
    W, 6096, 13, 2010/06/30, 10:55:04.414, 2449291477629, QTAgent32.exe, UIA : StopSession of the plugin called before StartSession

     

     

    Wednesday, June 30, 2010 11:10 AM

Answers

  • Madmaximillion/subwire

    You probably are trying to see the timer information in the test case result but this data is mainted in the test run statistics. Try running the same test as posted in this thread and click on link 'Test Run Completed' given in the test results window. Following is the output under Standard Console output section that I am getting if I run the same test code.

    Timer Results:
    Timer Name:      iteration1
    Start Time:      9/8/2010 12:26:17 AM
    End Time:        9/8/2010 12:26:18 AM
    Timer Duration:  00:00:01.0015398
    Timer Name:      iteration2
    Start Time:      9/8/2010 12:26:18 AM
    End Time:        9/8/2010 12:26:19 AM
    Timer Duration:  00:00:00.9997224
    Timer Name:      iteration3
    Start Time:      9/8/2010 12:26:19 AM
    End Time:        9/8/2010 12:26:20 AM
    Timer Duration:  00:00:01.0001708
    Timer Name:      iteration4
    Start Time:      9/8/2010 12:26:20 AM
    End Time:        9/8/2010 12:26:21 AM
    Timer Duration:  00:00:01.0002077
    Timer Name:      iteration5
    Start Time:      9/8/2010 12:26:21 AM
    End Time:        9/8/2010 12:26:22 AM
    Timer Duration:  00:00:01.0002168

    Tuesday, September 7, 2010 6:58 PM

All replies

  • Although I am using VS2010 I was expecting output as per scenario 2 in the below post which is pre 2010

     

    http://weblogs.asp.net/adilakhter/archive/2008/05/04/more-on-unit-testing-testcontext.aspx

    Wednesday, June 30, 2010 11:18 AM
  • No-one has had the same issue?
    Thursday, July 29, 2010 9:54 AM
  • Yes, I have the same issue. But I gave up on solution. Instead I'm using System.Diagnostics.Stopwatch class and its Start() and Stop() functions, and then just use TestContext to write out the Stopwatch.Elapsed.
    Tuesday, September 7, 2010 4:10 PM
  • Madmaximillion/subwire

    You probably are trying to see the timer information in the test case result but this data is mainted in the test run statistics. Try running the same test as posted in this thread and click on link 'Test Run Completed' given in the test results window. Following is the output under Standard Console output section that I am getting if I run the same test code.

    Timer Results:
    Timer Name:      iteration1
    Start Time:      9/8/2010 12:26:17 AM
    End Time:        9/8/2010 12:26:18 AM
    Timer Duration:  00:00:01.0015398
    Timer Name:      iteration2
    Start Time:      9/8/2010 12:26:18 AM
    End Time:        9/8/2010 12:26:19 AM
    Timer Duration:  00:00:00.9997224
    Timer Name:      iteration3
    Start Time:      9/8/2010 12:26:19 AM
    End Time:        9/8/2010 12:26:20 AM
    Timer Duration:  00:00:01.0001708
    Timer Name:      iteration4
    Start Time:      9/8/2010 12:26:20 AM
    End Time:        9/8/2010 12:26:21 AM
    Timer Duration:  00:00:01.0002077
    Timer Name:      iteration5
    Start Time:      9/8/2010 12:26:21 AM
    End Time:        9/8/2010 12:26:22 AM
    Timer Duration:  00:00:01.0002168

    Tuesday, September 7, 2010 6:58 PM