我有一个包含一个被忽略测试的小型NUnit测试套件。现在我正在编写一个简单的MSBuild脚本来进行还原、发布等操作。我尝试让dotnet test
任务正常运行。
<Target Name="test" DependsOnTargets="restore">
<Exec Command="dotnet test"
WorkingDirectory="test\Example.Tests" />
</Target>
但是,它每次都以-1的代码退出!
PS> dotnet msbuild /t:test build.xml
Microsoft (R) Build Engine version 15.3.409.57025 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Restore completed in 50.88 ms for C:\...\src\Example\Example.csproj.
Restore completed in 57.18 ms for C:\...\test\Example.Tests\Example.Tests.csproj.
Build started, please wait...
Build completed.
Test run for C:\...\test\Example.Tests\bin\Debug\netcoreapp1.1\Example.Tests.dll(.NETCoreApp,Version=v1.1)
Microsoft (R) Test Execution Command Line Tool Version 15.0.0.0
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
NUnit Adapter 3.8.0.0: Test execution started
Running all tests in C:\...\test\Example.Tests\bin\Debug\netcoreapp1.1\Example.Tests.dll
NUnit3TestExecutor converted 26 of 26 NUnit test cases
Skipped FilterEndpointWithCompletelyFilteredSystemsReturnsNotFound("foo")
EXEC : error Message: [C:\...\build.xml]
OneTimeSetUp: Having trouble constructing this scenario with the current command catalog
NUnit Adapter 3.8.0.0: Test execution complete
Total tests: 26. Passed: 25. Failed: 0. Skipped: 1.
Test Run Successful.
Test execution time: 2.8322 Seconds
C:\...\build.xml(16,9): error MSB3073: The command "dotnet test" exited with code -1.
如果我直接在控制台中运行命令,那就没问题了。
PS> dotnet test
Build started, please wait...
Build completed.
Test run for C:\...\test\Example.Tests\bin\Debug\netcoreapp1.1\Example.Tests.dll(.NETCoreApp,Version=v1.1)
Microsoft (R) Test Execution Command Line Tool Version 15.0.0.0
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
NUnit Adapter 3.8.0.0: Test execution started
Running all tests in C:\...\test\Example.Tests\bin\Debug\netcoreapp1.1\Example.Tests.dll
NUnit3TestExecutor converted 26 of 26 NUnit test cases
Skipped FilterEndpointWithCompletelyFilteredSystemsReturnsNotFound("foo")
Error Message:
OneTimeSetUp: Having trouble constructing this scenario with the current command catalog
NUnit Adapter 3.8.0.0: Test execution complete
Total tests: 26. Passed: 25. Failed: 0. Skipped: 1.
Test Run Successful.
Test execution time: 3.6485 Seconds
我搜寻了许多帮助资料,但并没有找到明确的答案。我的理解是,Exec task 会搜索 STDOUT 中是否包含某种错误信息,可能仅仅是单词“error”,以设置退出代码/状态。
出现在控制台上的确有此信息(由于某些原因,NUnit会为被忽略/跳过的测试打印“Error Message”)。
Skipped FilterEndpointWithCompletelyFilteredSystemsReturnsNotFound("foo")
Error Message:
OneTimeSetUp: Having trouble constructing this scenario with the current command catalog
如果我注释掉这个测试,运行就会通过(通过msbuild)。
关于Exec任务,我的理解是否正确?如果我覆盖CustomErrorRegularExpression参数,那么我会“修复”问题吗?我找不到有关此参数的任何好信息...我应该将其设置为空字符串吗?