如何使用MSBuild收集NUnit报告? [英] How to collect NUnit reports with MSBuild?

查看:79
本文介绍了如何使用MSBuild收集NUnit报告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近将NUnit引入了Visual Studio C#项目.项目文件夹结构看起来像

I've recently introduced NUnit to a Visual Studio C# project. The project folder structure looks like

- project root
-- applications (rich client interface, web interface, small tools)
-- components   (business logic)
-- vendor       (3rd party components)
-- tests        (Nunit tests)

对于在应用程序或组件下的每个Visual Studio项目"MyProject",在测试下都有一个对应的项目名为"MyProject.Test".当我介绍NUnit测试时,我在每个.Test.csproj文件中放置了以下内容:

For each Visual Studio project "MyProject" under applications or components there is a corresponding project under tests named "MyProject.Test". When I introduced the NUnit test, I put the following in each .Test.csproj file:

<Target Name="AfterBuild">
  <CreateItem Include="$(TargetPath)">
    <Output TaskParameter="Include" ItemName="MyProjectTests" />
  </CreateItem>
  <!-- Create folder for test results -->
  <MakeDir Directories="$(OutDir)\TestResults" />
  <!-- Run tests-->
  <NUnit Assemblies="@(MyProjectTests)" ToolPath="..\vendor\NUnit\bin" OutputXmlFile=".\TestResults\MyProject.Test.Results.xml" WorkingDirectory="$(OutDir)" />
  <!-- Create HTML report -->
  <Xslt Inputs="$(OutDir)\TestResults\MyProject.Test.Results.xml" Xsl="$(MSBuildCommunityTasksPath)\NUnitReport.xsl" RootTag="Root" Output="$(OutDir)\TestResults\MyProject.Test.Results.html" />
</Target>

这在从Visual Studio内部以及使用MSBuild CLI的构建服务器上构建解决方案时都可以正常工作.

This works fine, both when building solutions from within Visual Studio as well as on a build server with the MSBuild CLI.

该方法的最大不便之处在于,它使测试报告保留在每个测试项目输出文件夹的TestResults文件夹中,而我的解决方案的主输出文件夹中没有任何内容.所以,我的问题是:

The remaining inconvenience of that approach is that it leaves me with the test reports in a TestResults folder in each test projects output folder, but with nothing in my solution's main output folder. So, my question is:

在解决方案/启动项目的输出文件夹中收集生成的NUnit html报告的首选方法是什么?我应该在哪个.csproj文件中放置哪些MSBuild指令?我刚刚开始使用MSBuild,我不知道最佳实践...

What is the preferred way of collecting the resulting NUnit html reports in the solution's/startup project's output folder? What MSBuild instructions should I place in which .csproj file? I'm just getting started with MSBuild and I can't figure out the best practice...

它必须在Visual Studio和MSBuild CLI中都可以工作,但是我想那应该不成问题.

It has to work both in Visual Studio and with the MSBuild CLI, but that shouldn't be a problem, I guess.

谢谢

推荐答案

如果您有构建服务器,一种好的方法是使用配置为您的测试文件夹的虚拟路径设置站点.然后,您公司中的任何人都可以浏览 http://build.companydomain.local/yourapp/nunitreports/,托管在构建服务器的IIS上(如果构建服务器有一个).

If you have a build server, one good approach is to setup a site with a virtual path configured to your test folder. Then any person on your company can browse something like http://build.companydomain.local/yourapp/nunitreports/, hosted on the build server's IIS (in case your build server have one).

我正在使用覆盖率报告进行此操作.任何人都可以随时浏览它.希望对您有所帮助!

I'm doing this with my coverage reports. Any person can browse it at any moment. I hope it helps!

这篇关于如何使用MSBuild收集NUnit报告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆