2012-11-02 34 views
2

在NUnit中,我可以從context.Result.State得到測試結果。如果它的NUnit.Framework.TestState.Success,那麼我知道測試通過。如何從MSTest獲取測試結果狀態?

在MSTest中,我如何獲取該信息?

我看到context.Properties.Keys,但他們都沒有提到測試結果的狀態。

回答

6

使用TestContext.CurrentTestOutcome財產在TestCleanup方法:

[TestClass] 
public class UnitTest 
{ 
    private TestContext TestContext { get; set; } 

    [TestCleanup] 
    public void TestCleanup() 
    { 
     if (TestContext.CurrentTestOutcome == UnitTestOutcome.Passed) 
      //do something 
    } 

    [TestMethod] 
    public void TestMethod() 
    { 
    } 
} 
+0

你能告訴我怎樣才能得到實際的理由/日誌(指爲什麼我的測試案例失敗,上線數)在TestCleanup方法? – joinsaad