【问题标题】:Ignore a nunit test based on the data that is loaded in TestCaseSource根据 TestCaseSource 中加载的数据忽略 nunit 测试
【发布时间】:2013-11-07 21:26:01
【问题描述】:

我想根据给测试的输入忽略一个测试,我四处搜索并找到了几个解决方案,它们如下

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

但我需要的是,只有当我传递了真正的值时,它才应该忽略

Assert.Ignore(true);

我确实使用如下条件语句实现了我想要的目标

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

我觉得这不是最好的方法,我想知道是否有更好的方法。在此先谢谢你:)。我刚刚开始,对新手感到抱歉

【问题讨论】:

  • 如果你这样做你的单元测试是错误的。

标签: c# c#-4.0 nunit


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多