How do I install NUnit 3 console on Windows and run tests?
Asked Answered
K

4

45

I want to run tests from a console like this (being in any directory, the DLL file can be for a different .NET version):

$ nunit3-console test.dll

I googled a lot, but can't find how to set up this.

The official tutorial has nothing useful and is complete zero. Following it gets me nowhere: https://github.com/nunit/docs/wiki/Installation

Kape answered 3/8, 2017 at 11:10 Comment(4)
This section seems to explain how to do it pretty clearly?Surbeck
Downloaded zip contains no nunit3-console.exe, there is only nunitlite-runner.exe.Kape
Fair enough. They need to update their documentation, then. You could always backtrack to the release that still contains nunit3-console and download that.Surbeck
Seems to be a fair amount of downvotes here. I will say I found this question useful as googling and reading the docs were unclear.Microphotograph
K
55

It is hard to find, because there is a lot of outdated documentation, either for NUnit2 or NUnit3.

Steps:

  1. Official NUnit3 console installers are here: https://github.com/nunit/nunit-console/releases (path is different than in docs)
  2. Download NUnit.Console-*.msi package and install
  3. Add to system PATH variable this: C:\Program Files (x86)\NUnit.org\nunit-console
  4. Open command line
  5. Type:

    $ nunit3-console test.dll

// For running multiple test assemblies in parallel see: https://mcmap.net/q/374607/-use-nunit-console-runner-to-run-all-tests-under-a-folder

Kape answered 3/8, 2017 at 11:35 Comment(3)
I got the msi and installed it, but there's no NUnit folder created under Program Files or Program Files x86, do you know where else could it have been installed?Laurelaureano
@mickael: This is the default installation path. Try installing again, but check first installation path when choosing Custom installation.Kape
Don't forget to start a new command prompt etc to pickup new environment path varsPepin
R
2

I realize this thread is a bit dated, but here is how I run a specific SINGLE test.

  • install nunit-console (https://github.com/nunit/nunit-console/releases/latest)
  • Open a powershell window and run nunit3-console.exe with "--test" option set to reference the specific test you want to run (including namespace and class). and finally, provide the location of the assembly where the test can be found.

Example (paths need to be adjusted to point to your specific files):

& "C:\Program Files (x86)\NUnit.org\nunit-console\nunit3-console.exe" --test=MyApp.Mvc.WebTests.CardsControllerTests.TheNameOfYourTestMethod "c:\src\MyApp.Mvc.WebTests\bin\Debug\MyApp.Mvc.WebTests.dll"

Hope this helps someone.

Rori answered 18/11, 2019 at 22:2 Comment(0)
V
1

I am using NUnit3-console.exe with Selenium WebDriver to run my automation, all of which is written in C#. I have multiple environments set up under discreet logins of Windows Server 2012.

NUnit-Console doesn't have to be "installed", although the .msi is readily available. Instead, I use the .zip and extract the files to a directory, C:\Nunit, rather than allowing the invocation to resolve from the PATH. All invocations are from a Windows Forms scheduler in the form -

C:\Nunit\NUnit3-Console.exe -work:C:\Users\xxxx\Automation\TestResults\ -out:TestResult.xml --where "name =~ 'yyyy'" --p environment=qa;browser=Firefox;browserSizeX=1200;browserSizeY=800 "C:\QA_Libraries3\zzzz.dll"

The test parameters are passed on the command line and the NUnit results plus results from the test are extracted from the TestResult.xml which is distinct for each user (environment).

Vosges answered 23/7, 2018 at 21:8 Comment(0)
A
1

What I do and recommend is to add nuget package NUnit.ConsoleRunner. Note that there are similarly named packages (NUnit.Runners, NUnit.Console) that might work too, but I know that NUnit.ConsoleRunner for sure has the nunit3-console.exe in it ... well at least the version of the package that I'm using (3.4.1) does :) Sadly, nunit versioning and packaging seems to be messy. There are lots of old docs and packages that seems to overlap. And I can't find good/solid up-to-date docs.

Anyway, once you get that package then you can run the exe that's now under your packages directory. For me it's packages\NUnit.ConsoleRunner.3.4.1\tools\nunit3-console.exe. This works well for calling from a build automation script that is in the solution folder or knows how to find the solution folder.

There's another option that although is not a direct answer to your question does get to what I assume is your desire: to run your nunit3 tests from the command line. If you add package NUnit3TestAdapter, then you can use Visual Studio's built in runner, vstest. If you open a Developer Command Prompt (or PowerShell), then it can be run as 'vstest.console' (without path info since the exe is in the path env var). Of course it has its own command syntax to learn.

Assemble answered 6/8, 2020 at 13:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.