简体   繁体   中英

How to get FullName as TestName in NUnit

I have an abstract test class, that contains test methods. Then some classes that derive from this abstract class. The TestExplorer recognizes the class deriving from abstract class structure, but the testNames are only with abstract class. I would need to show NUNIT the fullName of test method, including the class, not only the abstract name.

  • the TestName pattern {M}{a} gives me: NUnitTestProject1.Tests.Test1("hello")

  • the FullName would be: NUnitTestProject1.NUnitTestProject1.Tests+TestImplement.NUnitTestProject1.Tests.NUnitTestProject1.Tests.Test1("hello")

I am missing the "TestImplementation1" class name. How can I tell NUnit to show the Full name as TestName (i need the "Tests+TestImplement1" information)? Great would be something global like runsettings file. TestExplorerView . I tried different nunit patterns, also runsettings file with <DisplayName>FullNameSep</DisplayName> .

thanks in advance!

simplyfied test class:

public abstract class Tests
{

    public class TestImplement1 : Tests
    {
    }

    public class TestImplement2 : Tests
    {
    }

    [Test]
    [TestCase("hello", TestName = "{M}{a}")]
    public void Test1(string param1)
    {
        Assert.Pass();
    }
}

Nice question!

I think what you're trying doesn't work, as the NUnit VS Adapter doesn't make use of "Test Names" in the NUnit sense. I'm not 100% sure on the history here, but I think it's because the Visual Studio side of the Test Explorer can't handle tests with the same name.

Instead, try looking at the DefaultTestNamePattern setting in the .runsettings file. The different options for patterns are defined on this page of the docs - I expect what you want {C}+{M}{a} - might need a bit of experimentation to get it exactly right.

As pointed out by the @pwasap4 - these exact format created by NUnit as a tests full name isn't currently accessible through the pattern functionality. It may well be possible for someone to add this feature however.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM