【问题标题】:How do I specify a set of tests using VSTest in a Pipeline如何在管道中使用 VSTest 指定一组测试
【发布时间】:2020-11-16 21:10:52
【问题描述】:

我想使用 azure 管道构建和运行 Web 服务测试。 使用 classic 管道构建器(而不是 YAML),我希望能够选择一组特定的测试来运行。我的测试分为不同的类别。每个班级都有许多测试。

如果我将过滤器字段留空,我将在所有类中运行所有测试。 但我想指定一类测试。我该怎么做?

我尝试了以下但没有找到测试

ClassName=WebServices.SocialTests

ClassName=SocialTests

Tests=SocialTests

Tests=WebServices.SocialTests

使用 Jenkins,我可以从命令行运行这些测试。我所要做的就是指定以下内容:

dotnet vstest mytests.dll /Tests:SocialTests

所以问题是为什么我不能在管道中做到这一点?

【问题讨论】:

  • 试试Name=SocialTests
  • 如何添加TestCategory,过滤:TestCategory=CategoryA,然后运行带有[TestCategory("CategoryA")]注解的测试?
  • 我没有使用类别。但我添加了它们,它们工作正常。
  • 使用“Name=”适用于类中的单个测试。不适用于该类中的所有测试。
  • @jpc 看来使用 TestCategory 可以工作,我会发布这个作为解决方法。

标签: azure-pipelines vstest


【解决方案1】:

作为解决方法,您可以将 TestCategory 添加到测试方法中,例如:--filter TestCategory=CategoryA,运行带有 [TestCategory("CategoryA")] 注释的测试。

namespace MSTestNamespace
{
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    [TestClass]
    public class UnitTestClass1
    {
        [Priority(2)]
        [TestMethod]
        public void TestMethod1(){
        
        }

        [TestCategory("CategoryA")]
        [Priority(3)]
        [TestMethod]
        public void TestMethod2(){
        }
    }
}

详情请参考此document

【讨论】:

    猜你喜欢
    • 2020-12-08
    • 2021-07-24
    • 2015-11-20
    • 2021-12-29
    • 2020-12-21
    • 2019-09-13
    • 2018-11-24
    • 2017-01-10
    • 2022-01-22
    相关资源
    最近更新 更多