Configuration files can be used to configure xUnit.net on a per test-assembly basis.
appDomain
culture
diagnosticMessages
failSkips
failWarns
internalDiagnosticMessages
longRunningTestSeconds
maxParallelThreads
methodDisplay
methodDisplayOptions
parallelAlgorithm
parallelizeAssembly
parallelizeTestCollections
preEnumerateTheories
seed
shadowCopy
showLiveOutput
stopOnFail
In these examples, we tell you to use the file name xunit.runner.json
.
You can also use <AssemblyName>.xunit.runner.json
(where
<AssemblyName>
is the name of your unit test assembly,
without the file extension like .dll
or .exe
).
You should only need to use this longer name format if your unit tests DLLs will
all be placed into the same output folder, and you need to disambiguate the
various configuration files.
The assembly-specific filename takes precedence over the non-specific filename;
there is no merging of values between files.
Add a new JSON file to the root of your test project. Name the file xunit.runner.json
.
Start with a schema reference so that text editors (like Visual Studio & Visual Studio Code) can
provide auto-complete behavior while editing the file:
Tell the build system to copy the file into the build output directory. Edit your .csproj
file and add the following:
The current schema is online at https://xunit.net/schema/current/xunit.runner.schema.json, which can be set in the JSON file to aid with intellisense from development IDEs like Visual Studio and Visual Studio Code.
Configuration elements are placed inside a top-level object:
All values in this table list the minimum runner version that is required to support the configuration value (previous versions will ignore unknown configuration values). Features that require support from the test framework itself will also list the minimum version of the test framework required for the feature; if you don't see a minimum test framework version, then it means the feature is implemented purely in the runners and works with all test framework versions.
Key | Supported Values |
---|---|
appDomain Runners v2 2.1+ Test Framework v1-v2 |
Set this value to determine whether App Domains are used. By default, they
will be used when available (the
JSON schema type: enum |
culture Runners v3+ Test Framework v3+ |
Set this value to override the default culture used to run all unit tests in
the assembly. You can pass
JSON schema type: string |
diagnosticMessages Runners v2 2.1+ Test Framework v2+ |
Set this value to
JSON schema type: boolean |
failSkips Runners v2 2.5+ Test Framework v1+ |
Set this to
JSON schema type: boolean |
failWarns Runners v3+ Test Framework v3+ |
Set this to
JSON schema type: boolean |
internalDiagnosticMessages Runners v2 2.1+ Test Framework v2+ |
Set this value to
JSON schema type: boolean |
longRunningTestSeconds Runners v2 2.2+ |
Set this value to enable long-running (hung) test detection. When the runner is
idle waiting for tests to finished, it will report that fact once the timeout
has passed. Use a value of NOTE: Long running test messages are diagnostic messages. You must enable diagnostic messages in order to see the long running test warnings.
JSON schema type: integer |
maxParallelThreads Runners v2 2.1+ Test Framework v2+ |
Set this to override the maximum number of threads to be used when parallelizing
tests within this assembly. Use a value of
1 NOTE: While this configuration value has been present since v2 2.1,
the newer values (
JSON schema type: integer (schema v2.1+), integer/string (schema v2.8+) |
methodDisplay Runners v2 2.1+ Test Framework v2+ |
Set this to override the default display name for test cases. If you set this
to
JSON schema type: enum |
methodDisplayOptions Runners v2 2.4+ Test Framework v2+ |
Set this to automatically perform transforms on default test names. This value
can either be
JSON schema type: string (comma separated flags) |
parallelAlgorithm Runners v2 2.8+ Test Framework v2 2.8+ |
Set this to change the way tests are scheduled when they're running in parallel. For more
information, see Running Tests in Parallel.
Note that the algorithm only applies when you have enabled
test collection parallelism, and are using a limited number of
threads (i.e., not
JSON schema type: enum |
parallelizeAssembly Runners v2 2.1+ Test Framework v2+ |
Set this to
JSON schema type: boolean |
parallelizeTestCollections Runners v2 2.1+ Test Framework v2+ |
Set this to
JSON schema type: boolean |
preEnumerateTheories Runners v2 2.1+ Test Framework v2+ |
Set this to
This value does not have a default, because it's up to each individual test runner
to decide what the best default behavior is. The Visual Studio adapter, for example,
will default to JSON schema type: boolean |
seed Runners v3+ Test Framework v3+ |
Set this to set the seed used for randomization (affects how the test cases are randomized). This is only valid for v3.0+ test assemblies; it will be ignored for v1 or v2 assemblies. If the seed value isn't set, then the system will determine a reasonable seed (and print that seed when running the test assembly, to assist you in reproducing order-dependent failures).
JSON schema type: integer |
shadowCopy Runners v2 2.1+ Test Framework v1-v2 |
Set this to
JSON schema type: boolean |
showLiveOutput Runners v2 2.8.1+ Test Framework v2+ |
Set this to
JSON schema type: boolean |
stopOnFail Runners v2 2.5+ Test Framework v2+ |
Set this to
JSON schema type: boolean |
3.0 (alpha 1) | https://xunit.net/schema/v3.0-alpha-1/xunit.runner.schema.json |
---|---|
2.1 (RC 1) | https://xunit.net/schema/v2.1-rc1/xunit.runner.schema.json |