【问题标题】:How do I output NUnit formatted xml with XUnit console?如何使用 XUnit 控制台输出 NUnit 格式的 xml?
【发布时间】:2020-09-17 23:55:44
【问题描述】:

我需要来自 XUnit 测试的 NUnit 输出作为报告。使用 NUnit,我可以做到:

nunit-console.exe /xml=c:\TestResultN.xml MyDll.dll

我试过了:

xunit.console MyDll.dll /nunit TestResults.xml

但我明白了:

unknown output transform: nunit

xunit 控制台上有什么好的文档吗?我找不到任何信息。

【问题讨论】:

    标签: xunit


    【解决方案1】:

    在控制台中输入 xunit.console.exe /? 并查看选项列表的末尾。

    > xunit.console.exe /?
    xUnit.net console test runner (64-bit .NET 2.0.50727.4952)
    Copyright (C) 2007-10 Microsoft Corporation.
    
    usage: xunit.console <xunitProjectFile> [options]
    usage: xunit.console <assemblyFile> [configFile] [options]
    
    Valid options:
      /silent                : do not output running test count
      /teamcity              : forces TeamCity mode (normally auto-detected)
      /wait                  : wait for input after completion
    
    Valid options for assemblies only:
      /noshadow              : do not shadow copy assemblies
      /xml <filename>        : output results to Xunit-style XML file
      /html <filename>       : output results to HTML file
      /nunit <filename>      : output results to NUnit-style XML file
    

    最后两个选项是从配置文件中提取的,由一个应用于 xunit 输出的 xslt 文件组成。如果 /nunit 不存在,请确保您在 xunit 目录中有 NUnitXml.xslt 文件,并且在 xunit.console.exe.config 文件中声明了条目 nunit

    我的xunit.console.exe.config 文件:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    
      <configSections>
        <section name="xunit" type="Xunit.ConsoleClient.XunitConsoleConfigurationSection, xunit.console"/>
      </configSections>
    
      <xunit>
        <transforms>
          <add
            commandline="html"
            xslfile="HTML.xslt"
            description="output results to HTML file"/>
          <add
            commandline="nunit"
            xslfile="NUnitXml.xslt"
            description="output results to NUnit-style XML file"/>
        </transforms>
      </xunit>
    
    </configuration>
    

    如果您找不到这些文件,您可能需要重新安装 xunit。

    【讨论】:

      【解决方案2】:

      首先点击此链接。 https://xunit.net/docs/getting-started/netfx/visual-studio

      然后从您的主项目文件夹中打开 cmd,如上面链接中所述。 xunit.console.exe的打开文件位置

      在 cmd 中运行以下命令:

      ....\packages\xunit.runner.console.2.4.1\tools\net472\xunit.console.exe Project.UnitTests\bin\Debug\Project.UnitTests.dll -xml test_ouput.xml 
      

      输出结果“test_ouput.xml”将保存在项目目录中。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-12-02
        • 2018-07-05
        • 2020-12-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-11-19
        相关资源
        最近更新 更多