1dotnet test command(1) .NET Core dotnet test command(1)
2
3
4
7 dotnet test - .NET test driver used to execute unit tests.
8
10 .NET Core 2.1
11 dotnet test [<PROJECT>] [-a|--test-adapter-path] [--blame] [-c|--configuration] [--collect] [-d|--diag] [-f|--framework] [--filter]
12 [-l|--logger] [--no-build] [--no-restore] [-o|--output] [-r|--results-directory] [-s|--settings] [-t|--list-tests]
13 [-v|--verbosity] [-- <RunSettings arguments>]
14
15 dotnet test [-h|--help]
16
17 .NET Core 2.0
18 dotnet test [<PROJECT>] [-a|--test-adapter-path] [-c|--configuration] [--collect] [-d|--diag] [-f|--framework] [--filter]
19 [-l|--logger] [--no-build] [--no-restore] [-o|--output] [-r|--results-directory] [-s|--settings] [-t|--list-tests] [-v|--verbosity]
20
21 dotnet test [-h|--help]
22
23 .NET Core 1.x
24 dotnet test [<PROJECT>] [-a|--test-adapter-path] [-c|--configuration] [-d|--diag] [-f|--framework] [--filter] [-l|--logger] [--no-build] [-o|--output] [-s|--settings] [-t|--list-tests] [-v|--verbosity]
25
26 dotnet test [-h|--help]
27
28 * * * * *
29
31 The dotnet test command is used to execute unit tests in a given
32 project. The dotnet test command launches the test runner console ap‐
33 plication specified for a project. The test runner executes the tests
34 defined for a unit test framework (for example, MSTest, NUnit, or xU‐
35 nit) and reports the success or failure of each test. If all tests are
36 successful, the test runner returns 0 as an exit code; otherwise if any
37 test fails, it returns 1. The test runner and the unit test library
38 are packaged as NuGet packages and are restored as ordinary dependen‐
39 cies for the project.
40
41 Test projects specify the test runner using an ordinary <PackageRefer‐
42 ence> element, as seen in the following sample project file:
43
44 [!code-xmlXUnit Basic Template]
45
46 Arguments
47 PROJECT
48
49 Path to the test project. If not specified, it defaults to current di‐
50 rectory.
51
53 .NET Core 2.1
54 -a|--test-adapter-path <PATH_TO_ADAPTER>
55
56 Use the custom test adapters from the specified path in the test run.
57
58 --blame
59
60 Runs the tests in blame mode. This option is helpful in isolating the
61 problematic tests causing test host to crash. It creates an output
62 file in the current directory as Sequence.xml that captures the order
63 of tests execution before the crash.
64
65 -c|--configuration {Debug|Release}
66
67 Defines the build configuration. The default value is Debug, but your
68 project’s configuration could override this default SDK setting.
69
70 --collect <DATA_COLLECTOR_FRIENDLY_NAME>
71
72 Enables data collector for the test run. For more information, see
73 Monitor and analyze test run.
74
75 -d|--diag <PATH_TO_DIAGNOSTICS_FILE>
76
77 Enables diagnostic mode for the test platform and write diagnostic mes‐
78 sages to the specified file.
79
80 -f|--framework <FRAMEWORK>
81
82 Looks for test binaries for a specific framework.
83
84 --filter <EXPRESSION>
85
86 Filters out tests in the current project using the given expression.
87 For more information, see the Filter option details section. For more
88 information and examples on how to use selective unit test filtering,
89 see Running selective unit tests.
90
91 -h|--help
92
93 Prints out a short help for the command.
94
95 -l|--logger <LoggerUri/FriendlyName>
96
97 Specifies a logger for test results.
98
99 --no-build
100
101 Doesn’t build the test project before running it. It also implicit
102 sets the --no-restore flag.
103
104 --no-restore
105
106 Doesn’t execute an implicit restore when running the command.
107
108 -o|--output <OUTPUT_DIRECTORY>
109
110 Directory in which to find the binaries to run.
111
112 -r|--results-directory <PATH>
113
114 The directory where the test results are going to be placed. If the
115 specified directory doesn’t exist, it’s created.
116
117 -s|--settings <SETTINGS_FILE>
118
119 Settings to use when running tests.
120
121 -t|--list-tests
122
123 List all of the discovered tests in the current project.
124
125 -v|--verbosity <LEVEL>
126
127 Sets the verbosity level of the command. Allowed values are q[uiet],
128 m[inimal], n[ormal], d[etailed], and diag[nostic].
129
130 RunSettings arguments
131
132 Arguments passed as RunSettings configurations for the test. Arguments
133 are specified as [name]=[value] pairs after “–” (note the space after
134 –). A space is used to separate multiple [name]=[value] pairs.
135
136 Example: dotnet test -- MSTest.DeploymentEnabled=false MSTest.MapIncon‐
137 clusiveToFailed=True
138
139 For more information about RunSettings, see vstest.console.exe: Passing
140 RunSettings args.
141
142 .NET Core 2.0
143 -a|--test-adapter-path <PATH_TO_ADAPTER>
144
145 Use the custom test adapters from the specified path in the test run.
146
147 -c|--configuration {Debug|Release}
148
149 Defines the build configuration. The default value is Debug, but your
150 project’s configuration could override this default SDK setting.
151
152 --collect <DATA_COLLECTOR_FRIENDLY_NAME>
153
154 Enables data collector for the test run. For more information, see
155 Monitor and analyze test run.
156
157 -d|--diag <PATH_TO_DIAGNOSTICS_FILE>
158
159 Enables diagnostic mode for the test platform and write diagnostic mes‐
160 sages to the specified file.
161
162 -f|--framework <FRAMEWORK>
163
164 Looks for test binaries for a specific framework.
165
166 --filter <EXPRESSION>
167
168 Filters out tests in the current project using the given expression.
169 For more information, see the Filter option details section. For more
170 information and examples on how to use selective unit test filtering,
171 see Running selective unit tests.
172
173 -h|--help
174
175 Prints out a short help for the command.
176
177 -l|--logger <LoggerUri/FriendlyName>
178
179 Specifies a logger for test results.
180
181 --no-build
182
183 Doesn’t build the test project before running it. It also implicit
184 sets the --no-restore flag.
185
186 --no-restore
187
188 Doesn’t execute an implicit restore when running the command.
189
190 -o|--output <OUTPUT_DIRECTORY>
191
192 Directory in which to find the binaries to run.
193
194 -r|--results-directory <PATH>
195
196 The directory where the test results are going to be placed. If the
197 specified directory doesn’t exist, it’s created.
198
199 -s|--settings <SETTINGS_FILE>
200
201 Settings to use when running tests.
202
203 -t|--list-tests
204
205 List all of the discovered tests in the current project.
206
207 -v|--verbosity <LEVEL>
208
209 Sets the verbosity level of the command. Allowed values are q[uiet],
210 m[inimal], n[ormal], d[etailed], and diag[nostic].
211
212 .NET Core 1.x
213 -a|--test-adapter-path <PATH_TO_ADAPTER>
214
215 Use the custom test adapters from the specified path in the test run.
216
217 -c|--configuration {Debug|Release}
218
219 Defines the build configuration. The default value is Debug, but your
220 project’s configuration could override this default SDK setting.
221
222 -d|--diag <PATH_TO_DIAGNOSTICS_FILE>
223
224 Enables diagnostic mode for the test platform and write diagnostic mes‐
225 sages to the specified file.
226
227 -f|--framework <FRAMEWORK>
228
229 Looks for test binaries for a specific framework.
230
231 --filter <EXPRESSION>
232
233 Filters out tests in the current project using the given expression.
234 For more information, see the Filter option details section. For more
235 information and examples on how to use selective unit test filtering,
236 see Running selective unit tests.
237
238 -h|--help
239
240 Prints out a short help for the command.
241
242 -l|--logger <LoggerUri/FriendlyName>
243
244 Specifies a logger for test results.
245
246 --no-build
247
248 Doesn’t build the test project before running it.
249
250 -o|--output <OUTPUT_DIRECTORY>
251
252 Directory in which to find the binaries to run.
253
254 -s|--settings <SETTINGS_FILE>
255
256 Settings to use when running tests.
257
258 -t|--list-tests
259
260 List all of the discovered tests in the current project.
261
262 -v|--verbosity <LEVEL>
263
264 Sets the verbosity level of the command. Allowed values are q[uiet],
265 m[inimal], n[ormal], d[etailed], and diag[nostic].
266
267 * * * * *
268
270 Run the tests in the project in the current directory:
271
272 dotnet test
273
274 Run the tests in the test1 project:
275
276 dotnet test ~/projects/test1/test1.csproj
277
278 Run the tests in the project in the current directory and generate a
279 test results file in the trx format:
280
281 dotnet test --logger:trx
282
283 Filter option details
284 --filter <EXPRESSION>
285
286 <Expression> has the format <property><operator><value>[|&<Expres‐
287 sion>].
288
289 <property> is an attribute of the Test Case. The following are the
290 properties supported by popular unit test frameworks:
291
292 Test Framework Supported properties
293 ──────────────────────────────────────
294 | MSTest | FullyQualifiedName Name ClassName Priority TestCategory | |
295 xUnit | FullyQualifiedName DisplayName Traits
296
297 |
298
299 The <operator> describes the relationship between the property and the
300 value:
301
302 Operator Function
303 ───────────────────────────
304 = Exact match
305 != Not exact match
306 ~ Contains
307
308 <value> is a string. All the lookups are case insensitive.
309
310 An expression without an <operator> is automatically considered as a
311 contains on FullyQualifiedName property (for example, dotnet test
312 --filter xyz is same as dotnet test --filter FullyQualifiedName~xyz).
313
314 Expressions can be joined with conditional operators:
315
316 Operator Function
317 ────────────────────
318 | OR
319 & AND
320
321 You can enclose expressions in parenthesis when using conditional oper‐
322 ators (for example, (Name~TestMethod1) | (Name~TestMethod2)).
323
324 For more information and examples on how to use selective unit test
325 filtering, see Running selective unit tests.
326
327 See also
328 · Frameworks and Targets
329
330 · .NET Core Runtime IDentifier (RID) catalog
331
332
333
334 dotnet test command(1)