How to run MSTest and show testing steps without Visual Studio (TE.exe)
有很多测试组的自动化使用的是Visual Studio MSTest,测试用例的执行需要通过visual studio来run/debug,运行的过程中我们只能看到一个In Progress的运行条,并不能知道程序执行到了哪一步或者在做什么……
微软提供的TE.EXE正好解决了这些问题,Te.exe可通过简单的command line在任何地方执行编译出的测试用例,还可以在CMD窗口逐条打出WexLogger展示case执行进度,基本的执行结果如截图:
TE的使用:
- 1. 安装
如果已经安装了WDK,TAEF的路径是 %programfiles%\Windows Kits\8.0\Testing\Runtimes\TAEF\
也可以跳过安装WDK这一步,直接copy TAEF folder来使用 (\\cossql1.gencos.com\UFIDA_HomeDir\AllUFIDAShared\Lydia\TAEF )
- 2. 使用
1) 将MSTest solution build出的所有相关.dll/.xml/.config…文件copy到测试执行路径(ex: D:\Run)
2) 执行cmd命令执行case,常用命令行:
I:\Lydia\TAEF\Te.exe D:\Run \MyTests.dll - run all the Unit Tests in MyTests.dll
I:\Lydia\TAEF\Te.exe D:\Run \MyTests.dll /name:*Tests - run the test method with name ‘Tests’ in MyTests.dll
Wex.logger的使用:
如果想要在CMD窗口显示程序过程logger,则需要引用TAEF的Wex.Logger.Interop.dll(using WEX.Logging.Interop;),常用的log methods:
Log.Comment(logMessage);
Log.Warning(logMessage);
Log.Error(logMessage);
Log.Result(TestResult.Passed, message);…
*需要注意的是,调用Wex.Logger.Interop.dll的solution在VS中run的时候会抛出格式错误的异常,解决这个问题,需要重新设置如下test settings:
Go to Test->Edit Test Settings->Local, set as following:
详细的TE使用可参见:https://msdn.microsoft.com/en-us/library/windows/hardware/hh439725(v=vs.85).aspx