visual-studio-code - 如何为 mstest 编写多线问题匹配器?
问题描述
我在多个文件中创建了许多失败的测试,以获得一些好看的输出。
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
}
]
}
}
无论我匹配方法名称前的“失败”一词还是断言后的“失败”一词,它都不起作用。如果我更改模式项目的顺序似乎没有帮助。
解决方案
推荐阅读
- python - Finding the row wise mean
- c# - 如何在 C# 中格式化字符串
- list - 这是什么数据?
- swift - 如何将(hstack)多个视频与 AVMutableVideoComposition 并排组合?
- vb.net - 整数值后的尾随百分比字符
- kotlin - Kotlin 错误“索引超出范围异常”
- netlogo - 基于代理和基于个体的建模(Railsback 和 Grimm,2019)NetLogo 商业模式
- fpdf - 我在第 526 行的 FPDF 文件中不断出现致命错误
- javascript - 使用 javascript 将 html 页面转换为 pdf 时,我无法看到图像
- python - 使用单个 API 调用的 Django REST 框架序列化器字段