Xunit Complete List of Command Line Options

Viewed 691

Does anybody have a complete list of command line options for running Xunit tests from the console?

I have around 100 tests, lets say broken up into 10 separate classes, each class has 10 tests

Class1 Test1 Test2 ...

Class2 Test1 Test2 ...

etc

I can trigger running all of these tests by navigating to my test directory and using 'dotnet test'. I have found documentation that says -? diplays all the command line options (but this isn't the full list apparently) https://livebook.manning.com/book/dotnet-core-in-action/appendix-b/4

The official documentation https://xunit.net/docs/running-tests-in-parallel says i can use for example '-parallel all' but when it run

dotnet test -parallel all

I get

\repos\test-automation-framework\framework>dotnet test -parallel all MSBUILD : error MSB1001: Unknown switch. Switch: -parallel

For switch syntax, type "MSBuild -help"

I would like to get to a stage where I can run all my tests in parallel but limit the thread count to lets say 6, so I will run my entire suite of tests, 6 tests at a time.

Am I missing something very obvious?

1 Answers

If I understand your question correctly, you want to pass some command line arguments to Xunit. But when you run dotnet test it actually applies arguments to dotnet command instead.

You can turn on parallelization and other features by using configuration files instead.

xunit.config.json

{
    "parallelizeAssembly": true
}

Arguments you did mention (e.g. --parallel) do exist but not in dotnet context. You can run Xunit manually by using console runner. It is present in NuGet and on GitHub as a part of xunit repo.

Here's it's output:

$ .\xunit.console.exe
xUnit.net Console Runner v2.4.1 (64-bit Desktop .NET 4.6.1, runtime: 4.0.30319.42000)
Copyright (C) .NET Foundation.

usage: xunit.console <assemblyFile> [configFile] [assemblyFile [configFile]...] [options] [reporter] [resultFormat filename [...]]

Note: Configuration files must end in .json (for JSON) or .config (for XML)

Valid options:
  -nologo                : do not show the copyright message
  -nocolor               : do not output results with colors
  -failskips             : convert skipped tests into failures
  -stoponfail            : stop on first test failure
  -parallel option       : set parallelization based on option
                         :   none        - turn off all parallelization
                         :   collections - only parallelize collections
                         :   assemblies  - only parallelize assemblies
                         :   all         - parallelize assemblies & collections
  -maxthreads count      : maximum thread count for collection parallelization
                         :   default   - run with default (1 thread per CPU thread)
                         :   unlimited - run with unbounded thread count
                         :   (number)  - limit task thread pool size to 'count'
  -appdomains mode       : choose an app domain mode
                         :   ifavailable - choose based on library type
                         :   required    - force app domains on
                         :   denied      - force app domains off
  -noshadow              : do not shadow copy assemblies
  -wait                  : wait for input after completion
  -diagnostics           : enable diagnostics messages for all test assemblies
  -internaldiagnostics   : enable internal diagnostics messages for all test assemblies
  -debug                 : launch the debugger to debug the tests
  -serialize             : serialize all test cases (for diagnostic purposes only)
  -trait "name=value"    : only run tests with matching name/value traits
                         : if specified more than once, acts as an OR operation
  -notrait "name=value"  : do not run tests with matching name/value traits
                         : if specified more than once, acts as an AND operation
  -method "name"         : run a given test method (can be fully specified or use a wildcard;
                         : i.e., 'MyNamespace.MyClass.MyTestMethod' or '*.MyTestMethod')
                         : if specified more than once, acts as an OR operation
  -nomethod "name"       : do not run a given test method (can be fully specified or use a wildcard;
                         : i.e., 'MyNamespace.MyClass.MyTestMethod' or '*.MyTestMethod')
                         : if specified more than once, acts as an AND operation
  -class "name"          : run all methods in a given test class (should be fully
                         : specified; i.e., 'MyNamespace.MyClass')
                         : if specified more than once, acts as an OR operation
  -noclass "name"        : do not run any methods in a given test class (should be fully
                         : specified; i.e., 'MyNamespace.MyClass')
                         : if specified more than once, acts as an AND operation
  -namespace "name"      : run all methods in a given namespace (i.e.,
                         : 'MyNamespace.MySubNamespace')
                         : if specified more than once, acts as an OR operation
  -nonamespace "name"    : do not run any methods in a given namespace (i.e.,
                         : 'MyNamespace.MySubNamespace')
                         : if specified more than once, acts as an AND operation
  -noautoreporters       : do not allow reporters to be auto-enabled by environment
                         : (for example, auto-detecting TeamCity or AppVeyor)

Reporters: (optional, choose only one)
  -appveyor              : forces AppVeyor CI mode (normally auto-detected)
  -json                  : show progress messages in JSON format
  -quiet                 : do not show progress messages
  -teamcity              : forces TeamCity mode (normally auto-detected)
  -verbose               : show verbose progress messages
  -vsts                  : forces VSTS CI mode (normally auto-detected)

Result formats: (optional, choose one or more)
  -xml <filename>        : output results to xUnit.net v2 XML file
  -xmlv1 <filename>      : output results to xUnit.net v1 XML file
  -html <filename>       : output results to HTML file
  -nunit <filename>      : output results to NUnit v2.5 XML file
  -junit <filename>      : output results to JUnit XML file
Related