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?
Create Test Runner Class It imports the JUnitCore class and uses the runClasses() method that takes the test class name as its parameter. Compile the Test case and Test Runner classes using javac. Now run the Test Runner, which will run the test case defined in the provided Test Case class. Verify the output.
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.
The nunit-console.exe program is a text-based runner and can be used when you want to run all your tests and don't need a red/yellow/green indication of success or failure. It is useful for automation of tests and integration into other systems.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With