Skip to content

Commit 10f162a

Browse files
Evangelinkgewarren
andauthored
MSTest: document testconfig.json (#43743)
Co-authored-by: Genevieve Warren <[email protected]>
1 parent e228461 commit 10f162a

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

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

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

101101
</RunSettings>
102102
```
103+
104+
## testconfig.json
105+
106+
When running your tests with MSTest, 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+
Starting with MSTest 3.7, you can also configure MSTest runs in the same configuration file. The following sections describe the settings that you can use in the `testconfig.json` file.
109+
110+
### MSTest element
111+
112+
MSTest settings are grouped by functionality that are described in the sections that follow.
113+
114+
| Entry | Default | Description |
115+
|-------|---------|-------------|
116+
| 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**. |
117+
| enableBaseClassTestMethodsFromOtherAssemblies | true | A value indicating whether to enable discovery of test methods from base classes in a different assembly from the inheriting test class. |
118+
| classCleanupLifecycle | EndOfAssembly | If you want the class cleanup to occur at the end of the class, set it to **EndOfClass**. |
119+
120+
#### AssemblyResolution settings
121+
122+
| Entry | Default | Description |
123+
|-------|---------|-------------|
124+
| 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" }`. |
125+
126+
#### Deployment settings
127+
128+
| Entry | Default | Description |
129+
|-------|---------|-------------|
130+
| deleteDeploymentDirectoryAfterTestRunIsComplete | true | To retain the deployment directory after a test run, set this value to **false**. |
131+
| deployTestSourceDependencies | true | Indicates whether the test source references are to be deployed. |
132+
| 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. |
133+
134+
#### Output settings
135+
136+
| Entry | Default | Description |
137+
|-------|---------|-------------|
138+
| 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. |
139+
140+
#### Parallelism settings
141+
142+
| Entry | Default | Description |
143+
|-------|---------|-------------|
144+
| enabled | false | Enable test parallelization. |
145+
| 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. |
146+
| 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. |
147+
148+
#### Execution settings
149+
150+
| Entry | Default | Description |
151+
|-------|---------|-------------|
152+
| considerEmptyDataSourceAsInconclusive | false | When set to `true`, an empty data source is considered as inconclusive. |
153+
| 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**. |
154+
| 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**. |
155+
| mapNotRunnableToFailed | true | A value indicating whether a not runnable result is mapped to failed test. |
156+
| treatClassAndAssemblyCleanupWarningsAsErrors | false | To see your failures in class cleanups as errors, set this value to **true**. |
157+
| treatDiscoveryWarningsAsErrors | false | To report test discovery warnings as errors, set this value to **true**. |
158+
159+
#### Timeout settings
160+
161+
| Entry | Default | Description |
162+
|-------|---------|-------------|
163+
| assemblyCleanup | 0 | Specify globally the timeout to apply on each instance of assembly cleanup method. |
164+
| assemblyInitialize | 0 | Specify globally the timeout to apply on each instance of assembly initialize method. |
165+
| classCleanup | 0 | Specify globally the timeout to apply on each instance of class cleanup method. |
166+
| classInitialize | 0 | Specify globally the timeout to apply on each instance of class initialize method. |
167+
| test | 0 | Specify globally the test timeout. |
168+
| testCleanup | 0 | Specify globally the timeout to apply on each instance of test cleanup method. |
169+
| testInitialize | 0 | Specify globally the timeout to apply on each instance of test initialize method. |
170+
| 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 behavior is more performant but relies on the user to correctly flow the token through all paths. |
171+
172+
> [!NOTE]
173+
> `[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.
174+
175+
### Example *testconfig.json* file
176+
177+
The following JSON shows the contents of a typical *.testconfig.json* file. Copy this code and edit it to suit your needs.
178+
179+
Each element of the file is optional because it has a default value.
180+
181+
```json
182+
{
183+
"platformOptions": {
184+
},
185+
"mstest": {
186+
"execution": {
187+
"mapInconclusiveToFailed" : true,
188+
"disableAppDomain": true,
189+
"considerFixturesAsSpecialTests" : false,
190+
},
191+
"parallelism" : {
192+
"enabled": true,
193+
"scope": "method",
194+
},
195+
"output": {
196+
"captureTrace": false
197+
}
198+
}
199+
}
200+
```

0 commit comments

Comments
 (0)