用于组合NUnit或MSTest XML结果的MSBuild任务

时间:2023-01-16 15:41:40

I have a set of NUnit XML result files (produced by xUnit.NET via the NUnitXml parameter to the Xunit.Runner.MSBuild.xunit msbuild task pretty much as in How do I get Team Build to show test results and coverage for xUnit.net test suite? and http://jonnekats.wordpress.com/2009/05/07/integrate-xunit-tests-into-your-daily-team-build/)

我有一组NUnit XML结果文件(由xUnit.NET通过NUnitXml参数生成到Xunit.Runner.MSBuild.xunit msbuild任务,就像我如何让Team Build显示测试结果和xUnit.net的覆盖范围一样测试套件?和http://jonnekats.wordpress.com/2009/05/07/integrate-xunit-tests-into-your-daily-team-build/)

The script publishes each of the test runs individually, which is slow as it pulls in all the TestResults artifacts each time. Thus I'd like to combine them into a single consolidated set on the client side first prior to submission [to TFS using mstest.exe with the /publish parameter].

该脚本单独发布每个测试运行,这很慢,因为它每次都会引入所有TestResults工件。因此,我想在提交之前将它们组合到客户端的单个整合集中[使用带有/ publish参数的mstest.exe进行TFS]。

xUnit.net has a CombineXunitXml Task which is invoked in xunit.tests.msbuild as follows:-

xUnit.net有一个CombineXunitXml任务,它在xunit.tests.msbuild中调用,如下所示: -

<CombineXunitXml InputFiles="@(TestXmlFiles)" OutputFile="TestResults.xml" />

Does anyone know of an equivalent task to merge NUnit result files in a similar way? (I'm guessing this doesnt arise as commonly as the NUnit task takes multiple assemblies in its Assemblies parameter whereas xUnit.net has a singular Assembly parameter).

有没有人知道以类似的方式合并NUnit结果文件的等效任务? (我猜这并不常见,因为NUnit任务在其Assemblies参数中采用多个程序集,而xUnit.net具有单一的Assembly参数)。

2 个解决方案

#1


The CombineXunitXml task does not exist in xUnit 1.1. Copying the class from the source for 1.5 (currently CTP2) into the solution for 1.1, it built just fine for me.

xUnit 1.1中不存在CombineXunitXml任务。将类从1.5(目前是CTP2)的源代码复制到1.1的解决方案中,它对我来说很好。

#2


I couldn't get Davy Brion's build task to work when I tried (the link in Atanas Korchev's answer).

当我尝试时,我无法让Davy Brion的构建任务工作(Atanas Korchev的答案中的链接)。

So we wrote an open source replacement:

所以我们写了一个开源代码:

https://github.com/15below/NUnitMerger

From the readme:

从自述文件:

Using in MSBuild

Load the task:

加载任务:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
             ToolsVersion="4.0"
             DefaultTargets="Build">
  <UsingTask AssemblyFile="$(MSBuildProjectDirectory)\..\Tools\MSBuild\15below.NUnitMerger.dll" TaskName="FifteenBelow.NUnitMerger.MSBuild.NUnitMergeTask" />
  ...

Feed it an array of files with in a target:

在目标中输入一组文件:

  <Target Name="UnitTest" DependsOnTargets="OtherThings">
    ... Generate the individual files here in $(TestResultsDir) ...

    <ItemGroup>
      <ResultsFiles Include="$(TestResultsDir)\*.xml" />
    </ItemGroup> 

    <NUnitMergeTask FilesToBeMerged="@(ResultsFiles)" OutputPath="$(MSBuildProjectDirectory)\TestResult.xml" />
  </Target>

Find the resulting combined results at OutputPath.

在OutputPath中查找生成的组合结果。

Using in F#

Create an F# console app and add 15below.NUnitMerger.dll, System.Xml and System.Xml.Linq as references.

创建一个F#控制台应用程序并添加15below.NUnitMerger.dll,System.Xml和System.Xml.Linq作为参考。

open FifteenBelow.NUnitMerger.Core
open System.IO
open System.Xml.Linq

// All my files are in one directory
WriteMergedNunitResults (@"..\testdir", "*.xml", "myMergedResults.xml")

// I want files from all over the place
let myFiles = ... some filenames as a Seq

myFiles
|> Seq.map (fun fileName -> XDocument.Parse(File.ReadAllText(fileName)))
|> FoldDocs
|> CreateMerged
|> fun x -> File.WriteAllText("myOtherMergedResults.xml", x.ToString())

#1


The CombineXunitXml task does not exist in xUnit 1.1. Copying the class from the source for 1.5 (currently CTP2) into the solution for 1.1, it built just fine for me.

xUnit 1.1中不存在CombineXunitXml任务。将类从1.5(目前是CTP2)的源代码复制到1.1的解决方案中,它对我来说很好。

#2


I couldn't get Davy Brion's build task to work when I tried (the link in Atanas Korchev's answer).

当我尝试时,我无法让Davy Brion的构建任务工作(Atanas Korchev的答案中的链接)。

So we wrote an open source replacement:

所以我们写了一个开源代码:

https://github.com/15below/NUnitMerger

From the readme:

从自述文件:

Using in MSBuild

Load the task:

加载任务:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
             ToolsVersion="4.0"
             DefaultTargets="Build">
  <UsingTask AssemblyFile="$(MSBuildProjectDirectory)\..\Tools\MSBuild\15below.NUnitMerger.dll" TaskName="FifteenBelow.NUnitMerger.MSBuild.NUnitMergeTask" />
  ...

Feed it an array of files with in a target:

在目标中输入一组文件:

  <Target Name="UnitTest" DependsOnTargets="OtherThings">
    ... Generate the individual files here in $(TestResultsDir) ...

    <ItemGroup>
      <ResultsFiles Include="$(TestResultsDir)\*.xml" />
    </ItemGroup> 

    <NUnitMergeTask FilesToBeMerged="@(ResultsFiles)" OutputPath="$(MSBuildProjectDirectory)\TestResult.xml" />
  </Target>

Find the resulting combined results at OutputPath.

在OutputPath中查找生成的组合结果。

Using in F#

Create an F# console app and add 15below.NUnitMerger.dll, System.Xml and System.Xml.Linq as references.

创建一个F#控制台应用程序并添加15below.NUnitMerger.dll,System.Xml和System.Xml.Linq作为参考。

open FifteenBelow.NUnitMerger.Core
open System.IO
open System.Xml.Linq

// All my files are in one directory
WriteMergedNunitResults (@"..\testdir", "*.xml", "myMergedResults.xml")

// I want files from all over the place
let myFiles = ... some filenames as a Seq

myFiles
|> Seq.map (fun fileName -> XDocument.Parse(File.ReadAllText(fileName)))
|> FoldDocs
|> CreateMerged
|> fun x -> File.WriteAllText("myOtherMergedResults.xml", x.ToString())