The console interface has a few additional options compared to the forms interface. The command line must always specify one or more file names. The console interface normally creates an XML representation of the test results. This file by default is called TestResult.xml and is placed in the working directory.
Note: By default the nunit-console program is not added to your path. You must do this manually if this is the desired behavior.
Note: Under the Windows operating system, options may be prefixed by either a forward slash or a hyphen. Under Linux, a hyphen must be used. Options that take values may use an equal sign, a colon or a space to separate the option from its value.
The console program must always have an assembly or project specified. To run the tests contained in the nunit.tests.dll use the following command:
nunit-console nunit.tests.dll
To run the tests in nunit.tests.dll through the Visual Studio project, use:
nunit-console nunit.tests.csproj
To run the same tests through an NUnit test project you have defined, use:
nunit-console nunit.tests.nunit
You may specify a test to be run by providing the full name of the test along with the containing assembly. For example to run NUnit.Tests.AssertionTests in the nunit.tests assembly use the following command:
nunit-console /run:NUnit.Tests.AssertionTests nunit.tests.dll
The name of the test to be run may be that of a test case, test fixture or a namespace containing tests.
You can specify multiple tests by separating names with commas (without spaces). For example:
nunit-console /run:NUnit.Tests.AssertionTests,NUnit.Tests.ConstraintTests nunit.tests.dll
Unlike the deprecated /fixture option, this option affects the running rather than the loading of the tests. Consequently it supports much broader use, including situations involving SetUpFixtures, which are not run if the class in question is not loaded. You should use /run in lieu of /fixture in almost every case.
You may specify a list of tests to be run by creating a separate file listing those tests and using the /runlist option:
nunit-console /runlist:testlist.txt nunit.tests.dll
The file 'testlist.txt' should contain the full name of each test, listed one per line. Each test named may be a test case, test fixture or a namesspace containing tests. Lines with the character '#' in the first column are treated as comments.
When specifying a fixture, you must give the full name of the test fixture along with the containing assembly. For example, to load the NUnit.Tests.AssertionTests in the nunit.tests.dll assembly use the following command:
nunit-console /fixture:NUnit.Tests.AssertionTests nunit.tests.dll
The name specified after the /fixture option may be that of a TestFixture class, a legacy suite (using the Suite property ) or a namespace. If a namespace is given, then all fixtures under that namespace are loaded.
This option is provided for backward compatibility. In most cases, you will be better served by using the /run option.
You may run tests from multiple assemblies in one run using the console interface even if you have not defined an NUnit test project file. The following command would run a suite of tests contained in assembly1.dll, assembly2.dll and assembly3.dll.
nunit-console assembly1.dll assembly2.dll assembly3.dll
Notes: You may specify multiple assemblies, but not multiple NUnit or Visual Studio projects on the command line. Further, you may not specify an NUnit or Visual Studio project together with a list of assemblies.
Beginning with NUnit 2.4, the console loads multiple assemblies specified in this way into separate AppDomains by default. You may provide a separate config file for each assembly. You may override the default by use of the /domain option.
Beginning with NUnit 2.4, the /fixture option, when used with multiple assemblies, will run tests matching the fixture name in all the assemblies. In earlier versions, only the first test found was executed.
When running tests from a Visual Studio or NUnit project, the first configuration found will be loaded by default. Usually this is Debug. The configuration loaded may be controlled by using the /config switch. The following will load and run tests for the Release configuration of nunit.tests.dll.
nunit-console nunit.tests.csproj /config:Release
Note: This option has no effect when loading an assembly directly.
NUnit provides CategoryAttribute for use in marking tests as belonging to one or more categories. Categories may be included or excluded in a test run using the /include and /exclude options. The following command runs only the tests in the BaseLine category:
nunit-console myassembly.dll /include:BaseLine
The following command runs all tests except those in the Database category:
nunit-console myassembly.dll /exclude:Database
Multiple categories may be specified on either option, by using commas to separate them.
Notes: Beginning with NUnit 2.4, the /include and /exclude options may be combined on the command line. When both are used, all tests with the included categories are run except for those with the excluded categories.
Beginning with NUnit 2.4.6, you may use a Category Expression with /include or /exclude. The table shows some examples:
Expression | Action |
---|---|
A|B|C | Selects tests having any of the categories A, B or C. |
A,B,C | Selects tests having any of the categories A, B or C. |
A+B+C | Selects only tests having all three of the categories assigned |
A+B|C | Selects tests with both A and B OR with category C. |
A+B-C | Selects tests with both A and B but not C. |
-A | Selects tests not having category A assigned |
A+(B|C) | Selects tests having both category A and either of B or C |
A+B,C | Selects tests having both category A and either of B or C |
Note: As shown by the last two examples, the comma operator is equivalent to | but has a higher precendence. Order of evaluation is as follows:
Note: Because the operator characters have special meaning, you should avoid creating a category that uses any of them in it's name. For example, the category "db-tests" could not be used on the command line, since it appears to means "run category db, except for category tests." The same limitation applies to characters that have special meaning for the shell you are using.
For a clear understanding of how category selection works, review the documentation for both the Category Attribute and the Explicit Attribute.
Most applications are written to run under a specific version of the CLR. A few are designed to operate correctly under multiple versions. In either case, it is important to be able to specify the CLR version to be used for testing.
Prior to NUnit 2.5, it was necessary to run the console program itself using the CLR version under which you wanted to run tests. This was done either by editing the nunit-console.exe.config file or by setting the COMPLUS_Version environment variable before running the program.
Under NUnit 2.5 and later versions, you may still use either of these approaches, but a simpler method is available.
The /framework option allows you to specify the version of the runtime to be used in executing tests. If that version specified is different from the one being used by NUnit, the tests are run in a separate process. For example, you may enter
nunit-console myassembly.dll /framework:net-1.1
This command will run tests under .NET 1.1 even if you are running the .NET 2.0 build of the nunit-console. Beginning with version 2.5.3, all versions of .NET through 4.0 as well as Mono profiles 1.0, 2.0 and 3.5 are supported.
Note: This option is not available using the .NET 1.1 build of nunit-console.
The /process option controls how NUnit loads tests in processes. The following values are recognized.
Note: This option is not available using the .NET 1.1 build of nunit-console.
The /domain option controls of the creation of AppDomains for running tests. The following values are recognized:
The default is to use multiple domains if multiple assemblies are listed on the command line. Otherwise a single domain is used.
The /apartment option may be used to specify the ApartmentState (STA or MTA) of the test runner thread. Since the default is MTA, the option is only needed to force execution in the Single Threaded Apartment.
Note: If a given test must always run in a particular apartment, as is the case with many Gui tests, you should use an attribute on the test rather than specifying this option at the command line.
The /timeout option takes an int value representing the default timeout to be used for test cases in this run. If any test exceeds the timeout value, it is cancelled and reported as an error. The default value may be overridden for selected tests by use of TimeoutAttribute.
Note: If you do not use this option, no timeout is set and tests may run for any amount of time.
Output created by the test, which is normally shown on the console, may be redirected to a file. The following command redirects standard output to the file TestResult.txt:
nunit-console nunit.tests.dll /out:TestResult.txt
The following command redirects standard error output to the StdErr.txt file.
nunit-console nunit.tests.dll /err:StdErr.txt
Note:This option only redirects output produced by the tests, together with selected NUnit output that is interspersed with the test output. It does not redirect all console output. If you want to redirect all output to a file, you should use command line redirection as supported by the shell you are using. This option exists for the purpose of separating test output from other output, such as the NUnit summary report.
The output from each test normally follows right after that of the preceding test. You may use the /labels option to cause an identifying label to be displayed at the start of each test case.
As stated above, the console program normally creates an XML representation of the test results. To change the name of the output file to "console-test.xml" use the following command line option:
nunit-console /result:console-test.xml nunit.tests.dll
The XML output may be entirely eliminated by use of the /noresult option.
Note: For compatibility with earlier releases, NUnit 2.6 also recognizes /xml and /noxml as synonyms for the /result and /noresult options.
Note: For additional information see the XML schema for the test results. This file is in the same directory as the executable and is called Results.xsd.
By default, all output files are created in the current directory. You may change the location for such files by specifying the /work option. For example, the following command would cause the TestResult.xml and Output.txt files to be created in the results directory.
nunit-console /work:results /out:Output.txt nunit.tests.dll
The /trace option allows you to control the amount of information that NUnit writes to its internal trace log. Valid values are Off, Error, Warning,Info and Debug. The default is Off.
The /noshadow option disables shadow copying of the assembly in order to provide improved performance.
The /nothread option suppresses use of a separate thread for running the tests and uses the main thread instead.
The /stoponerror option causes execution of the test run to terminate immediately on the first test failure or error.
The /wait option causes the program to wait for user input before exiting. This is useful when running nunit-console from a shortcut.
The /xmlconsole option displays raw XML output on the console rather than transforming it. This is useful when debugging problems with the XML format.
The /nologo option disables display of the copyright information at the start of the program.
The /cleanup option clears the shadow copy cache and exits.
The /help or /? option displays a brief help message