【问题标题】:Visual Studio Test Explorer with playlists带有播放列表的 Visual Studio 测试资源管理器
【发布时间】:2015-11-10 06:10:24
【问题描述】:

这可能与问题有关:Dynamic playlists of unit tests in visual studio

我希望能够拥有一个或多个测试播放列表,而不是将每个新测试都添加到某个播放列表中。

我目前有一个包含所有单元测试的播放列表,但将来我希望有一个包含自动化集成测试的播放列表,它应该在提交到 TFS 之前运行,而不是每次构建应用程序时运行。

有没有办法做到这一点?

【问题讨论】:

  • 你使用 nunit 还是 mstest?
  • 我使用 mstest。 @nozzleman

标签: c# visual-studio unit-testing test-explorer


【解决方案1】:

我不知道可以在 TFS 中使用的设置类型,因为我没有使用 TFS,但我知道可以在 NUnitMSTest

使用 NUnit 的解决方案

使用 NUnit,您可以使用 Category-Attribute 标记单个测试甚至整个夹具:

namespace NUnit.Tests
{
  using System;
  using NUnit.Framework;

  [TestFixture]
  [Category("IntegrationTest")]
  public class IntegrationTests
  {
    // ...
  }
}

namespace NUnit.Tests
{
  using System;
  using NUnit.Framework;

  [TestFixture]
  public class IntegrationTests
  {
    [Test]
    [Category("IntegrationTest")]
    public void AnotherIntegrationTest()
    { 
      // ...
    }
  }
}

也是唯一使用 nunit-console.exe 运行的:

nunit-console.exe myTests.dll /include:IntegrationTest

MSTest 解决方案

MSTest 的解决方案非常相似:

namespace MSTest.Tests
{
    [TestClass]
    public class IntegrationTests
    {
        [TestMethod]
        [TestCategory("IntegrationTests")
        public void AnotherIntegrationTest()
        {
        }
    }
}

但是这里你必须用那个属性标记所有的Test,它不能用来装饰整个类。

然后,和 NUnit 一样,只执行 IntegrationTests 类别中的那些测试:

使用 VSTest.Console.exe

Vstest.console.exe myTests.dll /TestCaseFilter:TestCategory=IntegrationTests

使用 MSTest.exe

mstest /testcontainer:myTests.dll /category:"IntegrationTests"

编辑

您还可以使用 VS 的 TestExplorer 执行某些测试类别。


(来源:s-msft.com

如上图所示,您可以在 TestExplorer 的左上角选择一个类别。选择 Trait 并仅执行您想要的类别。

请参阅MSDN 了解更多信息。

【讨论】:

  • 这几乎是我想做的。我现在设法使用 mstest 运行测试。这将在命令提示符下运行测试,所以我想使用 Visual Studio 中的内置测试资源管理器不支持这个? @nozzleman
  • 确定有,请参阅msdn.microsoft.com/en-us/library/hh270865.aspx。我会更新我的答案
  • 谢谢,太好了。几乎是我正在寻找的解决方案:)
猜你喜欢
  • 2013-11-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-25
  • 1970-01-01
相关资源
最近更新 更多