Visual Studio不会在测试类中运行所有单元测试

时间:2012-10-28 16:06:18

标签: c# visual-studio-2010 unit-testing testing

我的单元测试类中有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。

我做的其他两项测试怎么了?

3 个答案:

答案 0 :(得分:4)

吉利布,是的,我认为你在哪里。重新启动Visual Studio修复了问题。

答案 1 :(得分:4)

我注意到测试运行完成后测试显示为“未运行”。事实证明,由于在中途抛出了StackOverflowException,这些测试从未完成。

答案 2 :(得分:1)

我不止一次咬过我的是,测试项目没有经过检查,无法在解决方案配置中构建。