Reputation: 211
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)
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>
This works fine, both when building solutions from within Visual Studio as well as on a build server with the MSBuild CLI.
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:
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...
It has to work both in Visual Studio and with the MSBuild CLI, but that shouldn't be a problem, I guess.
Thanks
Upvotes: 1
Views: 1702
Reputation: 2797
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!
Upvotes: 1