How to execute NUnit test using NUnit.Runners package and psake?
Asked Answered
B

3

14

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?

Bewilderment answered 28/2, 2012 at 16:37 Comment(3)
So as far as I understand it correctly, you need a task that checks whether the runners are installed and if not, it runs nuget and installs the package?Drubbing
Yes, something like that. (Ideally, solution-level packages should have the auto-restore functionality built-in and I should simply call nunit-console.exe somewhere inside the packages folder but that will probably come only in some future version of NuGet.)Bewilderment
I was not aware that solution-level packages exist at all. How do you identity them? How does VS track that NUnit.Runners is already installed?Dancette
U
8

Just ran into this myself. Quite easy to fix as follows:

  1. Get latest version of the Nuget Package Manager extension. I'm on 1.8 at the moment.
  2. Add the Nunit.Runners package to your solution
  3. Copy the element related to the runner from packages.config under your .nuget folder into the packages.config file of your unit test project

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.

Uriiah answered 26/5, 2012 at 17:47 Comment(1)
The link to "build light on Github" is broken 404 :(, working link github.com/SouthsideSoftware/BuildLightMadid
R
2

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.

Reflex answered 19/10, 2012 at 16:46 Comment(0)
P
0

This doesn't answer your question, but may be of use to someone facing a similar problem. I ran into the same problem trying to set up a TeamCity build. I worked around this by reverting to an older version of nunit.

NUnit 2.5.10.11092 still has the nunit exe's in the nuget package.

Profiteer answered 20/3, 2012 at 18:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.