【问题标题】:Can I filter NUnit tests based on Property in Visual Studio test explorer我可以根据 Visual Studio 测试资源管理器中的属性过滤 NUnit 测试吗
【发布时间】:2019-12-11 12:22:45
【问题描述】:

是否可以构建一个 Visual Studio 测试资源管理器搜索表达式,该表达式实际上会根据 Property 属性的 name AND value 过滤 NUnit 测试?例如, 类似Trait:TestSize=Large。我似乎无法弄清楚如何让它工作,经过数小时的搜索,我不清楚我是否应该从 Visual Studio、NUnit 或 NUnit 测试适配器中寻找文档。

[TestFixture]
public class SampleTestFixture {
  [Test]
  [Property("TestSize", "Large")]
  public void Test1() { ... }
}

更多细节:

  • 目前使用的是 VS 2015,但我希望它可以在 VS 2017 和 2019 中使用
  • 使用 NUnit 3.12
  • 使用 NUnit3TestAdapter 3.8

【问题讨论】:

    标签: visual-studio visual-studio-2015 nunit nunit-3.0 nunittestadapter


    【解决方案1】:

    我不确定我是否理解正确,但如果你想过滤测试以根据 TestCaseName 运行你想要的,你应该使用 TestEngineAPI。 欲了解更多信息 - https://github.com/nunit/docs/wiki/Test-Engine-API

    ITestEngine engine = TestEngineActivator.CreateInstance();
    
    TestPackage package = new TestPackage("my.test.assembly.dll");
    
    ITestRunner runner = engine.GetRunner(package);
    
    // Run all the tests in the assembly
    XmlNode testResult = runner.Run(this, TestFilter.Empty);
    

    其中 TestFilter.Empty 可以是这样的: new TestFilter($"<filter><or><name>Test1</name></or></filter>");

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-25
      • 2016-12-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多