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

gan*_*jan 7 c# testing unit-testing visual-studio-2010

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

    }
}
Run Code Online (Sandbox Code Playgroud)

所以当我运行测试时,只执行sortTest2?我期待3个结果.我结果1/1通过了.TestName:sortTest2.

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

gan*_*jan 6

gillyb,是的,我认为你是对的。重新启动 Visual Studio 解决了该问题。


Lar*_*rin 5

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