2012-10-28 163 views
5

我在我的單元測試3種測試方法,但Visual Studio中只運行第二次測試,忽視了其他Visual Studio中不運行在一個測試類的所有單元測試

這些都是3種測試方法:

[TestClass()] 
public class InsertionSortTest 
{ 

    [TestMethod()] 
    public void sortTest() 
    { 
     InsertionSort target = new InsertionSort(); // TODO: Initialize to an appropriate value 
     int[] n = new int[] { 2, 1, 4 }; 
     int[] nExpected = new int[] { 1, 2, 4 }; 
     target.sort(ref n); 
     CollectionAssert.AreEqual(nExpected, n); 

    } 

    [TestMethod()] 
    public void sortTest2() 
    { 
     InsertionSort target = new InsertionSort(); // TODO: Initialize to an appropriate value 
     int[] n = new int[] { 1, 2 }; 
     int[] nExpected = new int[] { 1, 2 }; 
     target.sort(ref n); 
     CollectionAssert.AreEqual(nExpected, n); 

    } 

    [TestMethod()] 
    public void sortTest3() 
    { 
     InsertionSort target = new InsertionSort(); // TODO: Initialize to an appropriate value 
     int[] n = new int[] { 1, 2 }; 
     int[] nExpected = new int[] { 1, 2 }; 
     target.sort(ref n); 
     CollectionAssert.AreEqual(nExpected, n); 

    } 
} 

所以當我運行測試時只執行sortTest2?我期待從這3結果。我得到的結果1/1通過。測試名稱:sortTest2。

我做的其他兩項測試發生了什麼?

+1

聽起來像它只是運行一箇舊的編譯或類似的東西...嘗試清理緩存重新運行測試 – gillyb

+1

另外,請遵循.NET命名約定 - 並命名您的測試方法,以清楚它們的測試方法,重新排序。 (你可能不需要'ref',或者......) –

回答

4

gillyb,是的,你在哪裏我認爲正確。重新啓動Visual Studio修復了這個問題。

2

我注意到測試運行完成後,測試顯示爲「未運行」。原來這些測試從未完成,因爲中途拋出了StackOverflowException。

1

有些事情已經讓我多次陷入困境,那就是測試項目沒有被檢查在解決方案配置中構建。

相關問題