Command line test runner for VS 2012 comes with a parameter /logger where user can specify logger to be used. Two loggers shipped with VS are Console and Trx. Console logger is default logger that prints output of test execution to console window. Trx logger is can be used to generate trx file for test run (/logger:trx).
Here I am describing how to write a custom logger that can be used with vstest.console.exe
There are two requirements for custom test logger
1. Implement interface Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.ITestLogger
Interface can be found in “C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\Microsoft.VisualStudio.TestPlatform.ObjectModel.dll”
2. Assembly containing logger implementation to be present in place where extensions are searched like "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\Extensions"
Assembly can be installed with VSIX like test adapters. In that case use /UseVSIXExtensions parameter also.
ITestLogger has only one method
This function is used to hookup to following events in TestLoggerEvents
Each Event handler now can be used to log event however you want (in file, db, console, etc). Following example prints in on console:
Once binary is placed at proper location, above logger can be used as
vstest.console.exe <testdll> /logger:SimpleLogger