views:

38

answers:

3

When i run my unit tests, i would like to print out and read how long it takes to run a function. I tried using Console.WriteLine() Trace.WriteLine() but that didn't work. Anyone know the proper method i should be using?

I have the following unit test

[TestMethod()]
public void ProductSerializationTest()
{

    Stopwatch swSerialization = new Stopwatch();
    swSerialization.Start();
    SerializeProductsToXML(dummyProductList, XMLFolderPath);
    swSerialization.Stop();
    //Print out swSerialization.Elapsed value
 }
A: 

Did you try Debug.WriteLine?

AJ
That didn't work either but I didn't want to use it because it won't work when the build is in Release mode.
burnt1ce
+1  A: 

If you're using Visual Studio with its built-in testing support, the output of System.Diagnostics.Trace.WriteLine will go to the test results report. That is, after your test has run, double-click its entry in the Test Results list, and there will be a section called "Debug Trace" in the test run report.

Eric Smith
A: 

Since you're using Microsoft.VisualStudio.TestTools.UnitTesting, it would be most reasonable to call TestContext.WriteLine(). Here's how to use a TestContext.


Since I use TestDriven and NUnit, I just Console.WriteLine() and the messages show when I run tests with debugger.

David B