Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何中止测试方法继续运行_C#_Testing - Fatal编程技术网

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,我无法判断测试是否通过/失败,因为它实际上通过/失败了,还是因为测试环境问题。