DotNetSurfers

Latish Sehgal's Blog

Customizing Output for Unit Test Runner With MSTest

I was playing around with running unit tests (MSTest for this project) from the command line, and found the default console output too verbose (hundreds of tests in this project). I tried to figure out a way to customize the output, but the most promising option was Gallio, and I couldn’t get it to work with the latest version of MSTest. While searching the interwebs, I came across VSTest.Console that I was not familiar with before. Apparently the latest Visual Studio uses this instead of MSTest.exe to run the unit tests. While the output seemed as verbose as before, you can configure the loggers for it, and even create your own loggers by implementing ITestLogger (found in “C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\Microsoft.VisualStudio.TestPlatform.ObjectModel.dll”).

I created a simplistic logger that shows only the summary of the test run and details of the first failed unit test. You can see the code on Github. After dropping the compiled dll into “C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\Extensions”, Visual Studio was able to pick up the new logger. I also opened up the vstest.console.exe.config file and disabled the default console logger. Now I can run the tests using the following command:

vstest.console.exe /Settings:temp.runsettings /logger:SimpleLogger Sample.Tests.dll

P.S If you are interested in tools that make you more productive, and work with Sql Server Management Studio, you should check out SqlSmash.

Comments