如何设置 XUnit 测试的结果
How to set outcome of XUnit test
您可以使用 XUnit 手动设置测试结果吗?在我的一项测试中,我必须满足先决条件,如果失败,我需要将测试结果设置为 inconclusive。在 NUnit 中,您可以通过 Assert.Inconclusive()
、Assert.Fail()
等设置结果。我可以用 XUnit 做类似的事情吗?是否有一些最佳实践如何做到这一点?
我想你可以在你的弹药测试方法中使用 Assume.That 它在设置时不起作用,但你会在测试方法中使用它。
在 xUnit 中没有开箱即用的方法来做你想做的事。有关详细信息,请参阅 https://xunit.github.io/docs/comparisons.html。
但是 Assert.Fail("This test is failing") 可以使用 Assert.True(false, "This test is failing") 复制。
XUnit 中最接近 Assert.Inconclusive 的方法是使用 Skip 属性。但据我所知,没有办法通过方法调用这部分方式,就像使用 NUnit 的 Assert.Inconclusive.
一样
有人在此处为 v1.9 编写了 Assert.Skip 方法:https://github.com/xunit/xunit/blob/v1/samples/AssertExamples/DynamicSkipExample.cs, however it no longer compiles in v.2.2.0. Actually the xUnit authors seem to be antagonistic to inconclusive tests (https://xunit.codeplex.com/workitem/9691)。
您可以使用 XUnit 手动设置测试结果吗?在我的一项测试中,我必须满足先决条件,如果失败,我需要将测试结果设置为 inconclusive。在 NUnit 中,您可以通过 Assert.Inconclusive()
、Assert.Fail()
等设置结果。我可以用 XUnit 做类似的事情吗?是否有一些最佳实践如何做到这一点?
我想你可以在你的弹药测试方法中使用 Assume.That 它在设置时不起作用,但你会在测试方法中使用它。
在 xUnit 中没有开箱即用的方法来做你想做的事。有关详细信息,请参阅 https://xunit.github.io/docs/comparisons.html。
但是 Assert.Fail("This test is failing") 可以使用 Assert.True(false, "This test is failing") 复制。
XUnit 中最接近 Assert.Inconclusive 的方法是使用 Skip 属性。但据我所知,没有办法通过方法调用这部分方式,就像使用 NUnit 的 Assert.Inconclusive.
一样有人在此处为 v1.9 编写了 Assert.Skip 方法:https://github.com/xunit/xunit/blob/v1/samples/AssertExamples/DynamicSkipExample.cs, however it no longer compiles in v.2.2.0. Actually the xUnit authors seem to be antagonistic to inconclusive tests (https://xunit.codeplex.com/workitem/9691)。