xUnit等于MSTest的Assert.Inconclusive

时间:2016-01-05 11:03:26

标签: unit-testing mstest assert xunit assertion

以下MSTest代码的xUnit等价物是什么:

Assert.Inconclusive("Reason");

这给出了黄色测试结果,而不是通常的绿色或红色。我想声明由于某些条件而无法运行测试,并且在满足这些条件后应该重新运行测试。

3 个答案:

答案 0 :(得分:12)

在库中实现某些内容之前,最好的办法就是使用Xunit.SkippableFact

alarmManager.setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);

这至少会使它在列表中显示为黄色忽略的测试用例。

信用转到https://stackoverflow.com/a/35871507/537842

答案 1 :(得分:8)

一种方法是在SkipFact属性中使用Theory参数。

[Fact(Skip = "It's not ready yet")]
public void ReplaceTokensUnfinished()
{
    var original = "";
    var expected = "";
    var tokenReplacer = new TokenReplacer();
    var result = tokenReplacer.ReplaceTokens(original, _tokens); // (_tokens is initialised in a constructor)
    Assert.Equal(result, expected);
}

运行时给出了这个结果:

enter image description here

答案 2 :(得分:0)

我通常会这样做,

throw new Exception("Inconclusive");

是的,它显示为失败的测试,但是至少在某些不确定的情况下,您可以在测试中提出该要求。

我没有使用上面提到的skippablefact功能,但这听起来对我来说是一个很好的解决方案。