2012-01-04 53 views
-1

這是我想如何中止測試方法從繼續運行

[TestMethod] 
public static void T1() 
{ 
    if (...) 
     //continue the test 
    else 
     //abort the test from continueing. 
} 

我想從在繼續中止測試方法,如果它符合特定的條件。

+1

你就不能使用'Assert.IsTrue'? – 2012-01-04 06:05:38

+1

或相反Assert.Fail。但是,如果這樣做,這可能表明您測試得太多。當*測試*開始需要邏輯時尤其令人擔憂。 – 2012-01-04 06:08:34

+0

@EtiennedeMartel可能是我沒有清楚地呈現我所需要的。如果只使用hte Assert.IsTrue或Assert.IsFalse,我無法判斷測試是通過還是失敗,因爲它實際上是通過/失敗還是由於測試環境問題。 – QianLi 2012-01-04 06:38:35

回答

0
public static void T1() 
    { 
     if (...) 
     //continue the test 
     else 
     { 
      //abort the test from continueing. 
     return; //this will do the trick 
     } 
    } 
1

你就不能使用return語句

[TestMethod] 
public static void T1() 
{ 
    if (...) 
    { 
     //continue the test 
    } 
    else 
    { 
     return; 
    } 
}