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.
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.
Building on @NikolayP's answer:
- 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.
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.
Also you could follow this instruction: https://confluence.jetbrains.com/display/TCD9/Getting+Started+with+NUnit
Build is running on an agent, so you need to install NUnit3 on all of the agents where you want to run a build.
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.
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']"
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):
- Executable:
%teamcity.tool.NuGet.CommandLine.DEFAULT%\tools\nuget.exe
- Parameters:
install NUnit.Console -Version 3.7.0 -ExcludeVersion -OutputDirectory %system.teamcity.build.tempDir%\NUnit
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"
来源:https://stackoverflow.com/questions/33876102/how-to-install-nunit-3-nunit3-console-exe-in-teamcity-9-x