Skip to content

Commit 21e980b

Browse files
committed
MSTest: document testconfig.json
1 parent 6b2c951 commit 21e980b

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed

docs/core/testing/unit-testing-mstest-configure.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,97 @@ Each element of the file is optional because it has a default value.
100100

101101
</RunSettings>
102102
```
103+
104+
## testconfig.json
105+
106+
Starting with MSTest 3.7, when running your tests through MSTest runner (a.k.a Microsoft.Testing.Platform), you can use a `testconfig.json` file to configure the behavior of the test runner. The `testconfig.json` file is a JSON file that contains the configuration settings for the test runner. The file is used to configure the test runner and the test execution environment. For more information, refer to [Microsoft.Testing.Platform testconfig.json documentation](unit-testing-platform-config.md#testconfigjson).
107+
108+
### MSTest element
109+
110+
MSTest settings are grouped by functionality that are described in the sections below.
111+
112+
| Entry | Default | Description |
113+
|-------|---------|-------------|
114+
| orderTestsByNameInClass | false | If you want to run tests by test names both in Test Explorers and on the command line, set this value to **true**. |
115+
| enableBaseClassTestMethodsFromOtherAssemblies | true | A value indicating whether to enable discovery of test methods from base classes in a different assembly from the inheriting test class. |
116+
| classCleanupLifecycle | EndOfAssembly | If you want the class cleanup to occur at the end of the class, set it to **EndOfClass**. |
117+
118+
#### AssemblyResolution settings
119+
120+
| Entry | Default | Description |
121+
|-------|---------|-------------|
122+
| paths | None | You can specify paths to extra assemblies when finding and running unit tests. For example, use these paths for dependency assemblies that aren't in the same directory as the test assembly. You can specify a path in the shape `{ "path": "...", "includeSubDirectories": "true/false" }`. |
123+
124+
#### Deployment settings
125+
126+
| Entry | Default | Description |
127+
|-------|---------|-------------|
128+
| deleteDeploymentDirectoryAfterTestRunIsComplete | true | To retain the deployment directory after a test run, set this value to **false**. |
129+
| deployTestSourceDependencies | true |A value indicating whether the test source references are to be deployed. |
130+
| enabled | true | If you set the value to **false**, deployment items that you specify in your test method aren't copied to the deployment directory. |
131+
132+
#### Output settings
133+
134+
| Entry | Default | Description |
135+
|-------|---------|-------------|
136+
| captureTrace | false | Capture text messages coming from the `Console.Write*`, `Trace.Write*`, and `Debug.Write*` APIs that will be associated to the current running test. |
137+
138+
#### Parallelism settings
139+
140+
| Entry | Default | Description |
141+
|-------|---------|-------------|
142+
| enabled | false | Enable test parallelization. |
143+
| scope | class | The scope of parallelization. You can set it to `method`. The default, `class`, corresponds to running all tests of a given class sequentially but multiple classes in parallel. |
144+
| workers | 0 | The number of threads/workers to be used for parallelization. The default value maps to the number of processors on the current machine. |
145+
146+
#### Run settings
147+
148+
| Entry | Default | Description |
149+
|-------|---------|-------------|
150+
| considerEmptyDataSourceAsInconclusive | false | When set to `true`, an empty data source is considered as inconclusive. |
151+
| considerFixturesAsSpecialTests | false | To display `AssemblyInitialize`, `AssemblyCleanup`, `ClassInitialize`, `ClassCleanup` as individual entries in Visual Studio and Visual Studio Code `Test Explorer` and _.trx_ log, set this value to **true**. |
152+
| mapInconclusiveToFailed | false | If a test completes with an inconclusive status, it's mapped to the skipped status in **Test Explorer**. If you want inconclusive tests to be shown as failed, set the value to **true**. |
153+
| mapNotRunnableToFailed | true | A value indicating whether a not runnable result is mapped to failed test. |
154+
| treatClassAndAssemblyCleanupWarningsAsErrors | false | To see your failures in class cleanups as errors, set this value to **true**. |
155+
| treatDiscoveryWarningsAsErrors | false | To report test discovery warnings as errors, set this value to **true**. |
156+
157+
#### Timeout settings
158+
159+
| Entry | Default | Description |
160+
|-------|---------|-------------|
161+
| assemblyCleanup | 0 | Specify globally the timeout to apply on each instance of assembly cleanup method. |
162+
| assemblyInitialize | 0 | Specify globally the timeout to apply on each instance of assembly initialize method. |
163+
| classCleanup | 0 | Specify globally the timeout to apply on each instance of class cleanup method. |
164+
| classInitialize | 0 | Specify globally the timeout to apply on each instance of class initialize method. |
165+
| test | 0 | Specify globally the test timeout. |
166+
| testCleanup | 0 | Specify globally the timeout to apply on each instance of test cleanup method. |
167+
| testInitialize | 0 | Specify globally the timeout to apply on each instance of test initialize method. |
168+
| useCooperativeCancellation | false | When set to `true`, in case of timeout, MSTest will only trigger cancellation of the `CancellationToken` but will not stop observing the method. This is more performant but relies on user to correctly flow the token through all paths. |
169+
170+
> [!NOTE]
171+
> `[Timeout]` attribute specified on a method overrides the global timeout. For example, `[Timeout(1000)]` on a method marked with [AssemblyCleanup] will override the global `assemblyCleanup` timeout.
172+
173+
### Example *testconfig.json* file
174+
175+
The following json shows the contents of a typical *.testconfig.json* file. Copy this code and edit it to suit your needs.
176+
177+
Each element of the file is optional because it has a default value.
178+
179+
```json
180+
{
181+
"mstest": {
182+
"execution": {
183+
"mapInconclusiveToFailed" : true,
184+
"disableAppDomain": true,
185+
"considerFixturesAsSpecialTests" : false,
186+
},
187+
"parallelism" : {
188+
"enabled": true,
189+
"scope": "method",
190+
},
191+
"output": {
192+
"captureTrace": false
193+
}
194+
}
195+
}
196+
```

0 commit comments

Comments
 (0)