2015-06-25 120 views

回答

0

它有助於查看更多的實際測試,但由於Assert.Equals沒有返回值,因此可以將其分解爲多個步驟。

舉例來說,如果你有這樣的:

Assert.AreEqual(value1, value2); 

然後,你可以用這個代替它:其實

var areValuesEqual = (value1 == value2); 

Assert.IsTrue(areValuesEqual); 

if (!areValuesEqual) 
{ 
    // rest of testing logic 
} 
1

嗯, 「Asset.AreEqual」 接受三個參數 1.預期的結果in bool 2. bool的原始結果 3.錯誤信息

如果預期和原始不匹配我t會拋出一個錯誤,對於截圖你需要使用try-catch,我很久以前就用過了。

公共無效AreEqual(布爾預計,布爾結果,字符串評論= 「」,字符串pictureName = 「」){ 嘗試 { Assert.AreEqual(預期,因此,評論);

 } 
     catch 
     { 
      /// will capture a screenshot of errors 
      if (string.IsNullOrEmpty(pictureName) && !string.IsNullOrEmpty(comment)) 
      { 
       int length = comment.Replace(" ", string.Empty).Length; 
       if (length > 30) 
        length = 30; 
       pictureName = comment.Replace(" ", string.Empty).Substring(0, length); 
      } 
      pictureName = (pictureName == "" ? Guid.NewGuid().ToString() : pictureName); 
      GetScreenShot(pictureName); 

    // Getscreenshot function capture image for me u need to put your code here(before throw)  
      throw; 
     } 
    } 
相關問題