我在我的單元測試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。
我做的其他兩項測試發生了什麼?
聽起來像它只是運行一箇舊的編譯或類似的東西...嘗試清理緩存重新運行測試 – gillyb
另外,請遵循.NET命名約定 - 並命名您的測試方法,以清楚它們的測試方法,重新排序。 (你可能不需要'ref',或者......) –