简体   繁体   English

Visual Studio单元测试-“ XUnit格式?”

[英]Visual Studio Unit Test - “XUnit format?”

My taskmasters have tasked me with attempting to get output from Visual Studio Unit Tests for C#. 我的任务负责人要求我尝试从Visual Studio Unit Tests for C#中获取输出。 Evidently, our build environment can make use of output files in that format. 显然,我们的构建环境可以使用该格式的输出文件。 I hear rumors it is possible, but my Googling comes up empty. 我听说有可能,但我的Google搜寻空无一人。

Does anyone know how to accomplish this feat? 有人知道如何完成这项壮举吗?

You can run your tests with VSTest or MSTest from the command line to create a .trx file with your test results. 您可以从命令行使用VSTestMSTest运行测试,以创建带有测试结果的.trx文件。 This is the standard format used for Visual Studio Unit Test output. 这是用于Visual Studio单元测试输出的标准格式。

As mentioned in other answer, MSTest.exe will generate trx files that xUnit is able to parse. 如其他答案所述,MSTest.exe将生成xUnit能够解析的trx文件。

If you have one script that builds all your projects, you might want to execute all tests and aggregate all test results into one trx file for xUnit. 如果您有一个脚本可以构建所有项目,则可能要执行所有测试并将所有测试结果聚合到一个xUnit的trx文件中。 Good practice is to name all your test projects to end with '.Test'. 优良作法是将所有测试项目命名为以“ .Test”结尾。 All these projects compile into dll's and they will all end with '.Test.dll'. 所有这些项目都将编译为dll,并且都将以“ .Test.dll”结尾。

Then you can update your build script to pick up all test projects, by searching your repo for Test.dll files in a script like this: 然后,您可以通过在类似以下脚本的仓库中搜索Test.dll文件,来更新构建脚本以选择所有测试项目:

@SET _config=Release

@call "%VS110COMNTOOLS%vsvars32"
@setlocal enabledelayedexpansion enableextensions
@set list=
@for /R ".." %%x in (obj) do @(
    @set CTD=%%x
    @pushd !CTD!
    @for %%y in (%_config%\*Test.dll %_config%\*Tests.dll) do @set list=!list! /testcontainer:%%x\..\bin\%%y
    @popd
) 2>nul

@set list=%list:~1%

@del results.trx 2>nul
mstest %list% /resultsfile:results.trx /detail:stdout
@IF NOT %ERRORLEVEL%==0 (GOTO lbl_error)

:lbl_success
@ECHO Successfully ran tests.
@GOTO lbl_end

:lbl_error
@ECHO Failed to run tests.
@EXIT /b 1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM