根据TestCaseSource中加载的数据忽略nunit测试

时间:2013-11-07 13:14:18

标签: c# c#-4.0 nunit

我想根据给测试的输入忽略一个测试,我在周围搜索并发现了几个解决方案,它们如下

Assert.Ignore();
Assert.Inconclusive();

但我需要的是它应该忽略只有当我传递像

这样的真值时
Assert.Ignore(true);

我确实使用条件语句实现了我想要的,如下所示

if(ignoreTheTest)
{
Assert.Ignore();
}

我觉得这不是最好的方法,我想知道是否有更好的方法来做它。谢谢你提前:)。我刚刚开始,对不起新手阙

1 个答案:

答案 0 :(得分:1)

我从来没有使用过这个,但是如果你的投诉是关于每次我建议你将代码提取到方法时必须编写的if语句::

public static void Assert(Func<bool> cond, string message = "")
{
    if(cond())
    {
        Assert.Ignore(message);
    }
}