我有一个小的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会为忽略/跳过的测试打印“错误消息”)。
Skipped FilterEndpointWithCompletelyFilteredSystemsReturnsNotFound("foo")
Error Message:
OneTimeSetUp: Having trouble constructing this scenario with the current command catalog
如果我注释掉这个测试,则运行通过(通过msbuild)。
我对Exec任务是否正确?我会通过覆盖CustomErrorRegularExpression
参数来“解决”问题吗?我找不到关于这个参数的任何好信息......我会把它设置成一个空字符串吗?
答案 0 :(得分:4)
如果提供,Exec
checks首先针对CustomErrorRegularExpression
和CustomWarningRegularExpression
输出。如果这些不匹配或未提供,则Exec
然后uses以下RegEx:
new Regex
(
// Beginning of line and any amount of whitespace.
@"^\s*"
// Match a [optional project number prefix 'ddd>'], single letter + colon + remaining filename, or
// string with no colon followed by a colon.
+ @"(((?<ORIGIN>(((\d+>)?[a-zA-Z]?:[^:]*)|([^:]*))):)"
// Origin may also be empty. In this case there's no trailing colon.
+ "|())"
// Match the empty string or a string without a colon that ends with a space
+ "(?<SUBCATEGORY>(()|([^:]*? )))"
// Match 'error' or 'warning'.
+ @"(?<CATEGORY>(error|warning))"
// Match anything starting with a space that's not a colon/space, followed by a colon.
// Error code is optional in which case "error"/"warning" can be followed immediately by a colon.
+ @"( \s*(?<CODE>[^: ]*))?\s*:"
// Whatever's left on this line, including colons.
+ "(?<TEXT>.*)$",
RegexOptions.IgnoreCase | RegexOptions.Compiled
)
以下列example格式的行被解释为错误或警告(取决于这两个词中哪一个在“Cat。”部分中)。
Main.cs(17,20):Command line warning CS0168: The variable 'foo' is declared but never used -------------- ------------ ------- ------ ---------------------------------------------- Origin SubCategory Cat. Code Text
我会通过覆盖CustomErrorRegularExpression参数来“解决”问题吗?
修改强>
(问我自己:为什么在地球我最初说“Yup”时我的第二句话直接与此相反?)
不。 :)将IgnoreStandardErrorWarningFormat
设置为true
。来自您在问题中链接的documentation:
IgnoreStandardErrorWarningFormat
:可选Boolean
参数。
- 如果
false
,请在输出中选择与标准错误/警告格式匹配的行,并将其记录为错误/警告。- 如果
true
,请停用此行为。默认值为
false
。