C# 如何中止测试方法继续运行
这是我想要的C# 如何中止测试方法继续运行,c#,testing,C#,Testing,这是我想要的 [TestMethod] public static void T1() { if (...) //continue the test else //abort the test from continueing. } 如果某个测试方法符合特定条件,我想中止它继续运行。您不能只使用return语句吗 public static void T1() { if (...) //continue
[TestMethod]
public static void T1()
{
if (...)
//continue the test
else
//abort the test from continueing.
}
如果某个测试方法符合特定条件,我想中止它继续运行。您不能只使用return语句吗
public static void T1()
{
if (...)
//continue the test
else
{
//abort the test from continueing.
return; //this will do the trick
}
}
[TestMethod]
public static void T1()
{
if (...)
{
//continue the test
}
else
{
return;
}
}
您不能只使用
Assert.IsTrue
?或相反的Assert.Fail。然而,如果这样做,这可能是一个迹象,你正在测试太多。当测试开始需要逻辑时,这尤其令人不安。@EtiennedeMartel可能是我没有清楚地表达我所需要的。如果只是使用Assert.IsTrue或Assert.IsFalse,我无法判断测试是否通过/失败,因为它实际上通过/失败了,还是因为测试环境问题。