Traditionally, nunit-console.exe
has been included in the repository and on the build server (or any other machine) this EXE was called from some build script.
Now that the NUnit.Runners package is available I wonder how this could be used from a psake build script. It is a solution-level package so it doesn't leave any trace in packages.config
and cannot be auto-restored as other project-level packages so I guess one would need to call Install-Package
from the psake script, wait for the download and then execute the unit tests? Hopefully this download can be run only once and it will not slow down the build every time it runs. Or will it?
Use nunit-console.exe to run tests from the command line. This will run the unit tests and save the results in the results. xml file, which you can work with easily.
Nunit provides three different runners, which may be used to load and run your tests. The console runner, nunit-console.exe, is used for batch execution. The gui runner, nunit.exe, provides interactive loading and running of tests.
Just ran into this myself. Quite easy to fix as follows:
From now on, when you build, Nuget will pull down the Nunit.Runners packages if it is not on the machine. I then reference the Nunit runner from the package in my command line build.
I have this working in a little project I did for a TeamCity build light on Github. Packages.config in the unit test project has been modified as discussed above. You can look at the MSBuild file to see how I run tests from the command line. (build.proj, which references some targets and properties contained in the repository's tools\msbuild folder). You will need the latest Nuget Package Manager installed before you try to build in VS.NET or from the command line (clicktobuild.bat).
You should be able to port the idea of how to run Nunit console from the right location into psake quite easily.
I have created an issue with nuget developers, and proposed a fix.
Modify the nuget.targets file with the following changes:
In <PropertyGroup Condition=" '$(OS)' == 'Windows_NT'">
add this element:
<SolutionLevelPackagesConfig>$([System.IO.Path]::Combine($(SolutionDir), ".nuget\packages.config"))</SolutionLevelPackagesConfig>
In <PropertyGroup>
add this element:
<RestoreSolutionLevelCommand>$(NuGetCommand) install "$(SolutionLevelPackagesConfig)" -source "$(PackageSources)" $(RequireConsentSwitch) -solutionDir "$(SolutionDir) "</RestoreSolutionLevelCommand>
In <Target Name="RestorePackages" DependsOnTargets="CheckPrerequisites">
add this element before the RestoreCommand for WinNT:
<Exec Command="$(RestoreSolutionLevelCommand)"
LogStandardErrorAsError="true"
Condition="'$(OS)' == 'Windows_NT' And Exists('$(PackagesConfig)') And Exists('$(SolutionLevelPackagesConfig)')" />
This made my msbuild to restore the solution level packages.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With