Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install nUnit 3 nunit3-console.exe in TeamCity 9.x

NUnit 3.0 is supported by TeamCity 9.1.x now however you have to install the runner and specify the path to the nunit3.console.exe in the step. My question is where do I copy the nunit3-console.exe? Do I have to put this on all the agents? Do I put it in a directory on my main TeamCity server and it will get shared or pulled by the agents? There doesn't seem to be good documentation on where to copy these files so that all the agents can use them.

like image 675
Brett Mathe Avatar asked Nov 23 '15 16:11

Brett Mathe


People also ask

How do I install NUnit console?

Unzip the file or install the MSI and then if you would like be able to run nunit3-console from the command line, put the bin directory, containing nunit3-console.exe on your path. In your test assemblies, add a reference to nunit. framework. dll, using the copy in the subdirectory for the appropriate runtime version.

How do you run a NUnit test in TeamCity?

Using the NUnit console from the command line is the simplest way to run tests. TeamCity provides the following basic features of integration for the command line: reporting the test run information in Build Log while the tests are executing. reporting the test results upon the tests finish.

Where is NUnit exe?

By default the NUnit installation program places all of the files into the C:\Program Files\NUnit 2.4 directory.


2 Answers

You should have the NUnit console on the each agent where you would like to run NUnit tests.

The best option is:

  1. Add reference to the NuGet package (https://www.nuget.org/packages/NUnit.Runners/).

  2. To restore package you could use "NuGet Installer" build step, see following blog post: https://blog.jetbrains.com/teamcity/2013/08/nuget-package-restore-with-teamcity/

  3. After that you just set path like "packages\NUnit.Console.3.0.0\tools\nunit3-console.exe" from the restored NuGet package.

like image 178
NikolayP Avatar answered Oct 11 '22 17:10

NikolayP


Building on @NikolayP's answer:

  1. Add reference to the NuGet package (https://www.nuget.org/packages/NUnit.Runners/).
  2. To restore package you could use "NuGet Installer" build step, see following blog post: https://blog.jetbrains.com/teamcity/2013/08/nuget-package-restore-with-teamcity/
  3. After that you just set path like "packages\NUnit.Console.3.0.0\tools\nunit3-console.exe" from the restored NuGet package.

I wrote the following PowerShell script to determine the correct NUnit.ConsoleRunner package directory and populate a TeamCity variable before the NUnit task is run. It uses the most recent version of the NUnit.Console package.

$SrcDirectory = "%src.directory%"
$PackagesDirectory = Join-Path $SrcDirectory packages

$NUnitConsoleRunnerPackageDirectory = Get-ChildItem (Join-Path $PackagesDirectory NUnit.ConsoleRunner.*) | %{
    @{
        Directory = $_.FullName
        Version = [Version]::Parse(($_.Name -replace "NUnit.ConsoleRunner.",""))
    }
} | Sort-Object Version -Descending | Select-Object -First 1 | %{ $_.Directory }

if (!$NUnitConsoleRunnerPackageDirectory) {
    throw [IO.DirectoryNotFoundException] "NUnit console runner package directory not found"
}

Write-Output "##teamcity[setParameter name='nunit.consolerunner.directory' value='$NUnitConsoleRunnerPackageDirectory']"

Note that you'll need to define the src.directory variable to point to the directory that contains the packages directory on your build agent, or otherwise supply the necessary root directory for the PowerShell script to work. You'll also need to define the nunit.consolerunner.directory variable with a default value of empty.

The script will also throw an exception if, for whatever reason, an NUnit.ConsoleRunner directory could not be found.

like image 33
NathanAldenSr Avatar answered Oct 11 '22 19:10

NathanAldenSr