Configuration files can be used to configure xUnit.net on a per test-assembly basis.
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:
{
"$schema": "https://xunit.net/schema/current/xunit.runner.schema.json"
}
Tell the build system to copy the file into the build output directory. Edit your .csproj
file and add the following:
<ItemGroup>
<Content Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>The 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:
{
"$schema": "https://xunit.net/schema/current/xunit.runner.schema.json",
"enum-or-string-key": "value1",
"boolean-key": true,
"integer-key": 42
}| Key | Supported Values |
|---|---|
appDomain[Runners v2.1+] |
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.0+] |
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.1+] |
Set this value to
JSON schema type: boolean |
internalDiagnosticMessages[Runners v2.1+] |
Set this value to
JSON schema type: boolean |
longRunningTestSeconds[Runners v2.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.1+/3.0] |
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.1,
the newer values (
JSON schema type: integer |
methodDisplay[Runners v2.1+] |
Set this to override the default display name for test cases. If you set this
to
JSON schema type: enum |
methodDisplayOptions[Runners v2.4+] |
Set this to automatically perform transforms on default test names. This value
can either be
JSON schema type: string (comma separated flags) |
parallelizeAssembly[Runners v2.1+] |
Set this to
JSON schema type: boolean |
parallelizeTestCollections[Runners v2.1+] |
Set this to
JSON schema type: boolean |
preEnumerateTheories[Runners v2.1+] |
Set this to
JSON schema type: boolean |
shadowCopy[Runners v2.1+] |
Set this to
JSON schema type: boolean |