简体   繁体   English

如何在 NUnit 中获取 FullName 作为 TestName

[英]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. TestExplorer 识别从抽象类结构派生的类,但 testNames 仅用于抽象类。 I would need to show NUNIT the fullName of test method, including the class, not only the abstract name.我需要向 NUNIT 显示测试方法的 fullName,包括类,而不仅仅是抽象名称。

  • the TestName pattern {M}{a} gives me: NUnitTestProject1.Tests.Test1("hello") TestName 模式 {M}{a} 给了我: NUnitTestProject1.Tests.Test1("hello")

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

I am missing the "TestImplementation1" class name.我缺少“TestImplementation1”类名。 How can I tell NUnit to show the Full name as TestName (i need the "Tests+TestImplement1" information)?如何告诉 NUnit 将全名显示为 TestName(我需要“Tests+TestImplement1”信息)? Great would be something global like runsettings file.很棒的是像 runsettings 文件这样的全局文件。 TestExplorerView .测试资源管理器视图 I tried different nunit patterns, also runsettings file with <DisplayName>FullNameSep</DisplayName> .我尝试了不同的 nunit 模式,还使用<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.我认为您尝试的方法不起作用,因为 NUnit VS Adapter 没有使用 NUnit 意义上的“测试名称”。 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.我对这里的历史不是 100% 确定,但我认为这是因为测试资源管理器的 Visual Studio 端无法处理具有相同名称的测试。

Instead, try looking at the DefaultTestNamePattern setting in the .runsettings file.相反,请尝试查看 .runsettings 文件中的DefaultTestNamePattern设置。 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. 文档的此页面上定义了模式的不同选项 - 我希望您想要{C}+{M}{a} - 可能需要进行一些实验才能使其完全正确。

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.正如@pwasap4 所指出的那样,这些由 NUnit 创建的作为测试全名的确切格式目前无法通过模式功能访问。 It may well be possible for someone to add this feature however.但是,很可能有人添加此功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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