XUnit - TestCaseOrderer - 如果失败则中断

问题描述 投票:0回答:1

我使用此处描述的 PriorityOrderer : https://learn.microsoft.com/en-us/dotnet/core/testing/order-unit-tests?pivots=xunit

它工作正常,但如果测试失败我想打破。

看起来像这样的东西:

        foreach (TTestCase testCase in
            sortedMethods.Keys.SelectMany(
                priority => sortedMethods[priority].OrderBy(
                    testCase => testCase.TestMethod.Method.Name)))
        {
            yield return testCase;
            if (HasFailed(testCase))
            {
                yield break;
            }
        }

但是我找不到如何实现我的

hasFailed
功能

c# xunit
1个回答
0
投票

您是否尝试过启用 xUnit 的

stopOnFail
设置?

将此设置为

true
可在测试失败后停止运行进一步的测试。

xunit.runner.json

{
    "$schema": "https://xunit.net/schema/current/xunit.runner.schema.json",
    "stopOnFail": true
}

你的
.csproj

<ItemGroup>
    <Content Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
© www.soinside.com 2019 - 2024. All rights reserved.