0

基本上我正在使用MStest運行一組編碼的UI測試。在編碼的Ui測試運行期間製作自定義日誌

我想在測試運行時編寫自定義日誌文件。

例如在每次測試結束時,如果測試已經過去了我想添加一行,上面寫着「測試已通過」

這將最好出去一個TXT的文本文件。 並且我最終會將它輸出到電子郵件中,但現在不需要。

在每個測試結束一個基本的水平我是想這

if (this.testContextInstance.CurrentTestOutcome.Equals(true)) 
     { 
      string lines = "Passed."; 
      System.IO.StreamWriter file = new System.IO.StreamWriter("c:\test.txt"); 
      file.WriteLine(lines); 
      file.Close(); 
     } 
     else 
     { 
      string lines = "Failed."; 
      System.IO.StreamWriter file = new System.IO.StreamWriter("c:\test.txt"); 
      file.WriteLine(lines); 
      file.Close(); 
     } 
    } 

但我不完全瞭解CurrentTestOutcome方法。

目前我沒有得到任何文件輸出。

回答

1

CurrentTestOutcome是枚舉參見http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.testcontext.currenttestoutcome.aspxhttp://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.unittestoutcome.aspx。所以我不確定這個問題的this.testContextInstance.CurrentTestOutcome.Equals(true)是怎麼實現的。

類似下面應該表現出你想要的東西:

string lines = "Failed."; 
System.IO.StreamWriter file = new System.IO.StreamWriter("c:\test.txt"); 
file.WriteLine(this.testContextInstance.CurrentTestOutcome.ToString()); 
file.Close(); 
相關問題