我为多个文件创建了许多失败的测试,以获得了一些不错的输出。
Test run for c:\Users\anthony.mastrean.CORP\Work\gitlab.com\anthonymastrean\simplenetq\test\SimpleNetQ.Tests\bin\Debug\netcoreapp3.0\SimpleNetQ.Tests.dll(.NETCoreApp,Version=v3.0)
Microsoft (R) Test Execution Command Line Tool Version 16.0.1
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
Failed TestMethod1
Error Message:
Assert.Fail failed.
Stack Trace:
at SimpleNetQ.Tests.UnitTest1.TestMethod1() in c:\Users\anthony.mastrean.CORP\Work\gitlab.com\anthonymastrean\simplenetq\test\SimpleNetQ.Tests\UnitTest1.cs:line 11
Failed TestMethod2
Error Message:
Assert.Fail failed.
Stack Trace:
at SimpleNetQ.Tests.UnitTest1.TestMethod2() in c:\Users\anthony.mastrean.CORP\Work\gitlab.com\anthonymastrean\simplenetq\test\SimpleNetQ.Tests\UnitTest1.cs:line 17
Failed TestMethod1
Error Message:
Assert.Fail failed.
Stack Trace:
at SimpleNetQ.Tests.UnitTest2.TestMethod1() in c:\Users\anthony.mastrean.CORP\Work\gitlab.com\anthonymastrean\simplenetq\test\SimpleNetQ.Tests\UnitTest2.cs:line 11
Total tests: 3. Passed: 0. Failed: 3. Skipped: 0.
Test Run Failed.
Test execution time: 0.5951 Seconds
我算出了这个单行问题匹配器。但是,显然,它仅与文件和行匹配。
{
"label": "test",
"type": "process",
"group": {
"kind": "test",
"isDefault": true
},
"command": "dotnet",
"args": ["test"],
"problemMatcher": {
"fileLocation": ["absolute"],
"severity": "error",
"pattern": {
// https://regex101.com/r/SlyIHb/1
"regexp": "^\\s+at\\s+(.*)\\s+in\\s+(.*):line\\s+(\\d+)\\s*$",
"file": 2,
"line": 3
}
}
}
默认情况下,代码似乎将整个匹配行作为消息。让我们尝试做得更好。 mstest将消息分成两行是没有帮助的。
{
"label": "test",
"type": "process",
"group": {
"kind": "test",
"isDefault": true
},
"command": "dotnet",
"args": ["test"],
"problemMatcher": {
"fileLocation": ["absolute"],
"severity": "error",
"pattern": [
{
// "regexp": "^\\s+(.*)\\s+failed\\..*$",
"regexp": "^Failed\\s+(.*)\\s*$",
"message": 1
},
{
// https://regex101.com/r/SlyIHb/1
"regexp": "^\\s+at\\s+(.*)\\s+in\\s+(.*):line\\s+(\\d+)\\s*$",
"file": 2,
"line": 3
}
]
}
}
无论我在方法名称之前匹配单词“ Failed”还是在声明之后匹配单词“ Failed”,它都不起作用。如果更改模式项的顺序似乎没有帮助。