【发布时间】:2012-07-03 09:34:05
【问题描述】:
当我构建一个 Visual Studio 2010 项目时,我想使用 NUnit 运行单元测试并仅在某些测试失败时显示测试结果。
我在 Visual Studio 中设置了构建后事件来调用批处理文件,如下所示:
$(ProjectDir)RunUnitTest.bat "$(SolutionDir)packages\NUnit.Runners.2.6.0.12051\tools\nunit-console.exe" "$(TargetPath)"
然后在RunUnitTest.bat,我调用nunit-console.exe,传入测试项目dll。
@echo off
REM runner is the full path to nunit-console.exe
set runner=%1
REM target is the full path to the dll containing unit tests
set target=%2
"%runner%" "%target%"
if errorlevel 1 goto failed
if errorlevel 0 goto passed
:failed
echo some tests failed
goto end
:passed
echo all tests passed
goto end
:end
echo on
之后,NUnit 会生成包含测试结果的TestResult.xml,那么如何以用户友好的方式显示呢?最好能在 Visual Studio 中显示,但也可以打开其他选项。
【问题讨论】:
-
我强烈建议您简单地使用 VS 集成测试运行器:TestDriven.Net 在 VS 输出窗格中显示测试结果,而NCrunch 在您编写代码时自动(并且有选择地)运行所有测试。
标签: visual-studio-2010 unit-testing automation nunit