【发布时间】:2012-10-28 16:06:18
【问题描述】:
我的单元测试类中有 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 通过。测试名称:sortTest2。
我做的另外两个测试发生了什么?
【问题讨论】:
-
听起来它只是在运行旧的编译或类似的东西......尝试清理缓存并重新运行测试
-
顺便说一句,请遵循 .NET 命名约定 - 并命名您的测试方法,以便清楚它们正在排序的场景。 (你可能也不需要
ref……)
标签: c# visual-studio-2010 unit-testing testing