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

后端 未结 8 1062
没有蜡笔的小新
没有蜡笔的小新 2021-02-07 06:19

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

8条回答
  •  太阳男子
    2021-02-07 07:18

    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.

提交回复
热议问题