TestContext class is equipped with two public methods:
EndTimer, which allow measuring the execution time of an individual unit test. In this way, time required to execute code under test can be measured, and be recorded in reports (e.g., in associated
.trx files) as follows.
TestContext.BeginTimer("longRunningProcess"); //.. invoke actual code under test TestContext.EndTimer("longRunningProcess");
The following screenshot illustrates the report generated from running the above code.
To sum up, we illustrate how to use
TestContext to measure execution time of code under test. Check out the next post where we show how to report additional information in test result.
Other posts in this series includes:
On Unit Testing:
Usage of TestContext:
2 thoughts on “Performance Measurement with TestContext”
Where is the screenshot?
Hey, Indeed! It’s missing. Since this post is from long time back, I have to check if I can find it somewhere. Also, that the screenshot was merely showing the report and its format. I am not sure if it is off any importance.