请有人帮助我如何集成 XUnit 架构以利用 stopOnFail 功能。
如果单元测试失败,我想停止执行。
通过查看:https://xunit.net/docs/configuration-files
有错误的地方请指正,但我有:
在我的测试项目的根目录中添加了一个新文件:xunit.runner.json
更新了我的测试项目的 .csproj 文件以包括:
<ItemGroup>
<Content Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
我已将
https://xunit.net/schema/current/xunit.runner.schema.json
的全部内容添加到我的 xunit.runner.json 并将 stopOnFail 更新为以下内容:
"stopOnFail": {
"description": "Enable or disable stopping running further tests once a failed test has been recorded.",
"default": true,
"type": "boolean"
}
这不起作用,有人可以告诉我哪里出错了吗?
您不应链接到在线架构,而是应将架构文件
xunit.runner.schema.json
的内容复制到您的 xunit.runner.json
文件中。以下是您应该如何更新 xunit.runner.json 文件(更多信息此处):
{
"$schema": "https://xunit.net/schema/current/xunit.runner.schema.json",
"stopOnFail": true
}
文档第 1 步指出
将新的 JSON 文件添加到测试项目的根目录。将文件命名为 xunit.runner.json。从架构引用开始,以便文本编辑器(如 Visual Studio 和 Visual Studio Code)可以在编辑文件时提供自动完成行为
这意味着从包含架构文件的
url的
xunit.runner.json
文件开始,而不是架构文件的内容:
{
"$schema": "https://xunit.net/schema/current/xunit.runner.schema.json"
}
配置文件的 JSON 模式本身不是有效的配置文件,不要这样使用它。
$schema
属性就在那里,以便编辑者知道在哪里查找架构,以便他们可以帮助您进行验证。
然后,如果您继续阅读,您会发现
stopOnFail
属性是一个布尔值。因此,要启用它,您最终会得到生成的配置文件:
{
"$schema": "https://xunit.net/schema/current/xunit.runner.schema.json",
"stopOnFail": true
}