How can I execute a test case from Command Console using NUnit? I had set of Selenium Tests written in C# based on NUnit framework. I need to execute the test cases simply by running from command console.
In JUnit we can run test case from cmd as
java junit.swingui.TestRunner test.Run
How can we do above in NUnit?
Use nunit-console.exe
to run tests from the command line.
For example:
nunit-console.exe /xml:results.xml path/to/test/assembly.dll
This will run the unit tests and save the results in the results.xml file, which you can work with easily.
See the documentation for all of the various command line switches that are available.
I would like to add a few words about the latest version of NUnit. The name of the console application has changed to nunit3-console.exe
in NUnit 3. Information about all possible options can be found in the official documentation. For example, run all tests in the assembly (the results are saved into the TestResult.xml
file by default).
nunit3-console.exe path/to/test/assembly.dll
I've just find another nice solution:
Adding the following command to the "Build Events" / "Post-Build Events", will run the tests in Nunit-Gui automatically after the project has been built.
I hope this can be useful:
"C:\Program Files (x86)\NUnit 2.6.3\bin\nunit-x86.exe" $(TargetPath) /run
Visual Studio: 2017, 2019(Preview)
On Mac use below command:
nunit-console <path/to/project>/<project-name>/bin/Debug/<project-solution-name>.dll
For example:
nunit-console /Users/pratik/Projects/selenium-mac13/selenium-test/bin/Debug/selenium-test.dll