kroe761
kroe761

Reputation: 3534

Change test names for parameterized NUnit in VS Test Explorer

I am trying to integrate NUnit parameterized cross-browser tests using NUnit. I want the tests to appear in the Test Explorer window, which I've accomplished using the NUnit3TestAdaptor, but I have no way of differentiating the different tests. This is an example of the current TestFixture attributes on my class (following this example):

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
        }
}

This is how the tests appear in the Test Explorer:

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

The problem is that I have no way of knowing which NUnitTestOne is a Chrome test vs iPhone test. This is what I would prefer to see in the test explorer (or something like this)

-> NUnitTestOne
       Chrome
       iPhone
-> NUnitTestTwo
       Chrome
       iPhone

Ideally, something like this would be perfect:

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

But I could just be dreaming. Is there a way to accomplish what I need? Thanks!

edit:

When using TestName="Chrome", Test Explorer does this:

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

Which is...weird.

edit again:

Used Category and it worked! This is what was in the test explorer:

-> Chrome
       NUnitTestOne
       NUnitTestTwo
-> iPhone
       NUnitTestOne
       NUnitTestTwo

Upvotes: 1

Views: 1443

Answers (1)

devNull
devNull

Reputation: 4219

You were close with Name("Chrome"). Instead, the property you want to set in the TestFixture attribute is TestName:

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

You can see all of the other properties available on that attribute here.

Upvotes: 1

Related Questions