在TeamCity中的NUnit结果文件

3
使用TeamCity 8,如何生成/查找NUnit运行的结果文件?
我们目前还运行MsTest,它会生成一个TRX文件。然后我们使用一个TRX->HTML报告工具将报告传递给管理层。在TeamCity中,如何使用NUnit实现相同的功能?
现在我想我需要将NUnit作为CommandLine构建步骤执行,但考虑到有一个NUnit插件和MsTest插件提供了“Results file:”选项,这似乎很疯狂。
2个回答

6

TeamCity以不同的方式执行MSTest和NUnit。

NUnit不是通过NUnit控制台可执行文件运行,而是通过TeamCity自己的NUnit运行器运行。这使得TeamCity能够实时报告NUnit测试结果——执行测试3...4...5...of 78——并允许即时通知失败的测试,即使没有执行所有测试。

另一方面,MSTest直接通过MSTest可执行文件运行,没有实时报告。除了“正在进行”之外,没有任何进度。测试结果(包括任何失败)仅在运行完每个测试后报告。

TeamCity需要并解析MSTest TRX文件进行自己的报告,包括任何失败的报告,因此该文件也可供您使用。但是,NUnit报告文件是NUnit控制台的一部分,而不是TeamCity运行器的一部分,因此没有报告文件可提供。

如果您需要报告文件,则需要通过NUnit控制台运行NUnit测试。有几种方法可以做到这一点,其中只有一种是使用命令行步骤。但请注意,无论您使用哪种替代方案,都将失去实时报告。


1
谢谢Jay - 不幸的是,这是我采取的根本路线。遗憾的是,TeamCity内置的NUnit运行程序不会输出XML文件 :( - Ian Quigley

3
杰伊的描述是正确的;这是TeamCity的行为,使得这个任务无法直接完成。
不过已知有一个解决方法:

http://devnet.jetbrains.com/message/5218450#5218450

基本上,您需要手动调用TeamCity NUnit运行程序(例如来自MSBuild)。然后,运行程序可以输出一个result.xml文件(每个测试程序集一个)。这些结果文件必须合并回一个文件中,以模拟nunit-console的行为。
Davy Brion甚至已经发布了此任务的MSBuild任务。

http://web.archive.org/web/20080808215345/http://davybrion.com/blog/2008/07/using-teamcitys-nunit-support-while-keeping-the-output-around/

http://web.archive.org/web/20080809002009/http://davybrion.com/blog/stuff/

他已经删除了自己的博客,所以只能通过waybackmachine找回。如果那些链接也失效了,这里是代码片段:

NUnitMergeOutput

This task combines the output of multiple NUnit xml reports into one combined xml report.
The combined report will contain the results of each xml report that was fed to it, and it contains the total number of tests, failures, duration and overall success status of the entire test run.

To define the task:

<UsingTask AssemblyFile="$(MSBuildProjectDirectory)\Libs\Brion.MSBuildTasks\Brion.MSBuildTasks.dll"
           TaskName="NUnitMergeOutput"/>

And to use it in a target:

<CreateItem Include="TestResults\*.xml" >
  <Output TaskParameter="Include" ItemName="NUnitOutputXmlFiles"/>
</CreateItem>

<NUnitMergeOutput NUnitOutputXmlFiles="@(NUnitOutputXmlFiles)"
                  PathOfMergedXmlFile="TestResults\TestResults.xml" /> 

BuildTeamCityNUnitArguments

TeamCity doesn’t easily allow you to enable its integrated NUnit testing support while still keeping the NUnit output xml files around after the build. This task prepares an xml arguments file to pass to TeamCity’s NUnitLauncher task which does make it possible to keep the NUnit output xml in a directory you can specify. You can find more info on this problem here and more info on this workaround here.

To define the task:

<UsingTask AssemblyFile="$(MSBuildProjectDirectory)\Libs\Brion.MSBuildTasks\Brion.MSBuildTasks.dll"
        TaskName="BuildTeamCityNUnitArguments"/>

And to use it in a target:

<CreateItem Include="**\Bin\Debug\*Tests*.dll" >
  <Output TaskParameter="Include" ItemName="TestAssemblies" />
</CreateItem>

<BuildTeamCityNUnitArguments HaltOnError="true" HaltOnFirstTestFailure="true"
                            HaltOnFailureAtEnd="true" TestAssemblies="@(TestAssemblies)"
                            NUnitResultsOutputFolder="TestResults"
                            PathOfNUnitArgumentsXmlFile="nunitarguments.xml" />


<Exec Command="$(teamcity_dotnet_nunitlauncher) @@ nunitarguments.xml" />

我在想现在是否有更好的方法来完成这个任务,因为现在是TC 8.0和2014年,而不是2008年上面那些东西被写出来时。 - Martin Suchanek
жҲ‘йңҖиҰҒжҺўзҙўиҝҷдёӘй—®йўҳзҡ„еҺҹеӣ жҳҜеӣ дёәеҪ“йҖҡиҝҮе‘Ҫд»ӨиЎҢжһ„е»әжӯҘйӘӨжҲ–PowerShellжһ„е»әжӯҘйӘӨжү§иЎҢnunit-consoleж—¶пјҢжҲ‘зңӢеҲ°дәҶеҘҮжҖӘзҡ„иЎҢдёәпјҲз–‘дјјиө„жәҗеҢ®д№ҸпјүгҖӮиҖҢTC nunitиҝҗиЎҢеҷЁдјјд№ҺдјҳеҢ–еҫ—жӣҙеҘҪгҖӮ - Martin Suchanek

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