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 t
Try latest version of script @NathanAldenSr
Still required variable http://teamcityserver/admin/editProject.html?projectId=yourId&tab=projectParams add nunit.consolerunner.directory parameter to Configuration Parameters
$SrcDirectory = "%teamcity.build.checkoutDir%"
$PackagesDirectory = Join-Path $SrcDirectory packages
Write-Output "PackagesDirectory" $PackagesDirectory
$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"
}
$NUnitConsoleRunnerPackageDirectory = Join-Path $NUnitConsoleRunnerPackageDirectory tools
Write-Output "NUnitConsoleRunnerPackageDirectory" $NUnitConsoleRunnerPackageDirectory
Write-Output "##teamcity[setParameter name='nunit.consolerunner.directory' value='$NUnitConsoleRunnerPackageDirectory']"
Build is running on an agent, so you need to install NUnit3 on all of the agents where you want to run a build.
I know that it is now July of 2018, but none of these answers were clear to me. Why do I need to install a console on each agent. There has to be a better way. When I was adding my Build Step for running tests, I noticed that the text under the input for the path to the NUnit console tool said, "Paths relative to the checkout directory are supported." All I did was added the nuget packages to my test project in my solution. I added the NUnit version v3.10.1 and then the NUnit.Console v3.8.0. Then in Team City I simply added the relative path "packages\NUnit.ConsoleRunner.3.8.0\tools\nunit3-console.exe"
You should have the NUnit console on the each agent where you would like to run NUnit tests.
The best option is:
Add reference to the NuGet package (https://www.nuget.org/packages/NUnit.Runners/).
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/
After that you just set path like "packages\NUnit.Console.3.0.0\tools\nunit3-console.exe" from the restored NuGet package.
Also building on @NikolayP's answer:
NuGet currently supports the command line argument -ExcludeVersion
for the install
operation. From the docs:
Installs the package to a folder named with only the package name and not the version number.
This results in a path that is rather easy to use in a subsequent NUnit runner build step and allows to drop the clever workaround of @NathanAldenSr.
As of TeamCity 2017.1.3 (and probably earlier versions), this feature is even exposed as a parameter for the NuGet Installer runner (see the Restore Options) but requires a solution path. The example below is suitable for a generic on-the-fly and transient installation of NUnit.
For easy copy and paste (adjust the NUnit version to your requirements):
%teamcity.tool.NuGet.CommandLine.DEFAULT%\tools\nuget.exe
install NUnit.Console -Version 3.7.0 -ExcludeVersion -OutputDirectory %system.teamcity.build.tempDir%\NUnit
There are some gotchas around the TeamCity runner - specifically, its default behaviour is not to run the specs in their own AppDomains with their own base directory, as per NUnit2 (and the NUnit3 Visual Studio Test Adapter).
There is a (currently undocumented) configuration property in the TeamCity 9.x build series that enables you to change this behaviour. I've written about it here.