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 always 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.
To run the tests in nunit.tests.dll through the Visual Studio project, use:
To run the same tests through an NUnit test project you have defined, use:
When specifying a fixture, you must give the full name of the test fixture along with the containing assembly. For example, to run 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 run. This option may be used with Visual Studio or NUnit projects as well.
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.
When only one version of the CLR is used, the config files for nunit-gui and nunit-console may be set up to specify that version. As a more convenient alternative when switching CLRs, you may use the provided clr.bat command to specify the version under which NUnit should run.
For example, to run the tests in nunit.tests.dll under the RTM version of the .Net 2.0 framework, use:
clr net-2.0 nunit-console nunit.tests.dll
The clr.bat file is located in the NUnit bin directory. You may put this on your path, or copy it to a convenient location. Enter clr /? for a list of options.
Note: If you use a <startup> section in the config file, it takes precedence over this option.
Note: This command is specific to the Microsoft .Net framework. The Mono framework provides other means to specify the version to be used when running a command.
NUnit 2.2 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.
Note:In the current release, you may choose to either include or exclude categories in a run, but not both. For a clear understanding of how category selection works, review the documentation for both the Category Attribute and the Explicit Attribute.
The output that is normally shown on the console may be redirected to a file. This includes output created by the test program as well as what NUnit itself creates. The following command redirects standard output to the TestResult.txt file:
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
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 always 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 /xml:console-test.xml nunit.tests.dll
The console interface uses XSLT to transform the test results from the XML file to what is printed to the screen when the program executes. The console interface has a default transformation that is part of the executable. To specify your own transformation named "myTransform.xslt" use the following command line option:
nunit-console /transform:myTransform.xslt nunit.tests.dll
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. The default transform Summary.xslt is located in the core source directory.
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.
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
Note: 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. The /fixture option may be used with multiple assemblies but it's more efficient to simply specify the assembly that contains the fixture.
The /noshadow option disables shadow copying of the assembly in order to provide improved performance.
The /thread option causes a separate thread to be created for running the
tests. This is necessary in cases where the tests must run in a particular type
of apartment. By running in a separate thread, the ApartmentState and
ThreadPriority settings under the
Note:The apartment state of the console program may change from release to release, so users requiring a particular apartment should take advantage of this setting rather than relying on the default.
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 /help or /? option displays a brief help message