C# 忽略基于TestCaseSource中加载的数据的nunit测试
我想忽略一个基于测试输入的测试,我四处搜索并找到了几个解决方案,它们如下C# 忽略基于TestCaseSource中加载的数据的nunit测试,c#,c#-4.0,nunit,C#,C# 4.0,Nunit,我想忽略一个基于测试输入的测试,我四处搜索并找到了几个解决方案,它们如下 Assert.Ignore(); Assert.Inconclusive(); 但我需要的是,只有当我传递了真正的值,比如 Assert.Ignore(true); 我确实用下面的条件语句实现了我想要的 if(ignoreTheTest) { Assert.Ignore(); } 我觉得这不是最好的方法,我想知道是否有更好的方法。提前谢谢:)。我才刚开始,很抱歉我从来没有用过这个,但如果您的抱怨是关于每次都必须编写的
Assert.Ignore();
Assert.Inconclusive();
但我需要的是,只有当我传递了真正的值,比如
Assert.Ignore(true);
我确实用下面的条件语句实现了我想要的
if(ignoreTheTest)
{
Assert.Ignore();
}
我觉得这不是最好的方法,我想知道是否有更好的方法。提前谢谢:)。我才刚开始,很抱歉我从来没有用过这个,但如果您的抱怨是关于每次都必须编写的if语句,我建议您将代码提取到一个方法中:
public static void Assert(Func<bool> cond, string message = "")
{
if(cond())
{
Assert.Ignore(message);
}
}
publicstaticvoid断言(Func-cond,stringmessage=”“)
{
if(cond())
{
Assert.Ignore(消息);
}
}
我从未使用过这个,但如果您的投诉是关于每次都必须编写的if语句,我建议您将代码提取到一个方法中:
public static void Assert(Func<bool> cond, string message = "")
{
if(cond())
{
Assert.Ignore(message);
}
}
publicstaticvoid断言(Func-cond,stringmessage=”“)
{
if(cond())
{
Assert.Ignore(消息);
}
}
如果这样做,则单元测试是错误的。如果这样做,则单元测试是错误的。