如何使用XUnit控制台输出NUnit格式的xml?

8
我需要从XUnit测试中获取NUnit输出,以便生成报告。使用NUnit可以执行以下操作:
nunit-console.exe /xml=c:\TestResultN.xml MyDll.dll

我已经尝试过:
xunit.console MyDll.dll /nunit TestResults.xml

但是我得到了:
unknown output transform: nunit

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

2个回答

21

在控制台中键入 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。


0

首先请点击此链接。 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_output.xml" 将保存在项目目录中。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接