![](/img/trans.png)
[英]Visual Studio Unit tests: run initialization code before each test
[英]Visual Studio does not run all the unit tests in a test class
我的單元測試類中有3個測試方法,但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通過了。 TestName:sortTest2。
我做的其他兩個測試怎么了?
我注意到測試運行完成后測試顯示為“未運行”。 原來這些測試從未完成,因為StackOverflowException被拋向中途。
吉利布,是的,我認為你在哪里。 重新啟動Visual Studio修復了問題。
我不止一次咬過我的東西是沒有檢查測試項目是否在解決方案配置中構建。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.