【问题标题】:Change test names for parameterized NUnit in VS Test Explorer在 VS 测试资源管理器中更改参数化 NUnit 的测试名称
【发布时间】:2019-02-15 00:01:13
【问题描述】:

我正在尝试使用 NUnit 集成 NUnit 参数化跨浏览器测试。我希望测试出现在我使用 NUnit3TestAdaptor 完成的测试资源管理器窗口中,但我无法区分不同的测试。这是我班级当前 TestFixture 属性的一个示例(遵循this 示例):

namespace Demo
{
    [TestFixture("Chrome", "72", "Windows 10", "", "")]
    [TestFixture("safari", "12.0", "iOS", "iPhone 8 Simulator", "portrait")]
    public class UNitTests
    {
        [Test]
        public void NUnitTestOne()
        {
            // Test Stuff
        }

        [Test]
        public void NUnitTestOne()
        {
            // Test Stuff
        }
}

这是测试在测试资源管理器中的显示方式:

-> Demo.UNitTests.NUnitTestOne
       NUnitTestOne
       NUnitTestOne
-> Demo.UNitTests.NUnitTestTwo
       NUnitTestTwo
       NUnitTestTwo

问题是我无法知道哪个NUnitTestOne 是 Chrome 测试与 iPhone 测试。这是我希望在测试资源管理器中看到的(或类似的东西)

-> NUnitTestOne
       Chrome
       iPhone
-> NUnitTestTwo
       Chrome
       iPhone

理想情况下,这样的事情会很完美:

[TestFixture("Chrome", "72", "Windows 10", "", ""), Name("Chrome")]
[TestFixture("safari", "12.0", "iOS", "iPhone 8 Simulator", "portrait"), Name("iPhone")]

但我可能只是在做梦。有没有办法完成我需要的?谢谢!

编辑:

使用 TestName="Chrome" 时,测试资源管理器会这样做:

   NUnitTestOne
   NUnitTestOne
   NUnitTestTwo
   NUnitTestTwo
-> Demo.UNitTests.NUnitTestOne
       NUnitTestOne
       NUnitTestOne
-> Demo.UNitTests.NUnitTestTwo
       NUnitTestTwo
       NUnitTestTwo

这……很奇怪。

再次编辑:

使用类别,它工作!这是测试资源管理器中的内容:

-> Chrome
       NUnitTestOne
       NUnitTestTwo
-> iPhone
       NUnitTestOne
       NUnitTestTwo

【问题讨论】:

    标签: c# visual-studio nunit test-explorer


    【解决方案1】:

    您与Name("Chrome") 关系密切。相反,您要在TestFixture 属性中设置的属性是TestName

    [TestFixture("Chrome", "72", "Windows 10", "", "", TestName = "Chrome")]
    [TestFixture("safari", "12.0", "iOS", "iPhone 8 Simulator", "portrait", TestName = "iPhone")]
    

    您可以查看该属性here 上的所有其他可用属性。

    【讨论】:

    • 我在问题中添加了一些代码,显示了添加 TestName 做了什么……它实际上使情况变得更糟,这很奇怪。不过谢谢!
    • 感谢您提供文档链接!我使用了类别并且它有效!我把结果放在问题中。谢谢!
    • 使用TestFixtureSource的时候呢?那我该如何设置测试名称呢?
    猜你喜欢
    • 2016-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多