【问题标题】:Visual Studio does not run all the unit tests in a test classVisual Studio 不会运行测试类中的所有单元测试
【发布时间】: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


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    我注意到测试运行完成后测试显示为“未运行”。结果这些测试从未完成,因为中途抛出了 StackOverflowException。

    【讨论】:

      【解决方案3】:

      让我不止一次感到困扰的是,测试项目没有被检查为在解决方案配置中构建。

      【讨论】:

        猜你喜欢
        • 2020-07-23
        • 1970-01-01
        • 1970-01-01
        • 2011-02-10
        • 1970-01-01
        • 2011-10-04
        • 2022-07-11
        • 2013-07-29
        • 2011-04-19
        相关资源
        最近更新 更多