@@ -219,6 +219,66 @@ fn it_works() {
219
219
This is a very common use of ` assert_eq! ` : call some function with
220
220
some known arguments and compare it to the expected output.
221
221
222
+ # The ` ignore ` attribute
223
+
224
+ Sometimes a few specific tests can be very time-consuming to execute. These
225
+ can be disabled by default by using the ` ignore ` attribute:
226
+
227
+ ``` rust
228
+ #[test]
229
+ fn it_works () {
230
+ assert_eq! (4 , add_two (2 ));
231
+ }
232
+
233
+ #[test]
234
+ #[ignore]
235
+ fn expensive_test () {
236
+ // code that takes an hour to run
237
+ }
238
+ ```
239
+
240
+ Now we run our tests and see that ` it_works ` is run, but ` expensive_test ` is
241
+ not:
242
+
243
+ ``` bash
244
+ $ cargo test
245
+ Compiling adder v0.0.1 (file:///home/you/projects/adder)
246
+ Running target/adder-91b3e234d4ed382a
247
+
248
+ running 2 tests
249
+ test expensive_test ... ignored
250
+ test it_works ... ok
251
+
252
+ test result: ok. 1 passed; 0 failed; 1 ignored; 0 measured
253
+
254
+ Doc-tests adder
255
+
256
+ running 0 tests
257
+
258
+ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
259
+ ```
260
+
261
+ The expensive tests can be run explicitly using ` cargo test -- --ignored ` :
262
+
263
+ ``` bash
264
+ $ cargo test -- --ignored
265
+ Running target/adder-91b3e234d4ed382a
266
+
267
+ running 1 test
268
+ test expensive_test ... ok
269
+
270
+ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
271
+
272
+ Doc-tests adder
273
+
274
+ running 0 tests
275
+
276
+ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
277
+ ```
278
+
279
+ The ` --ignored ` argument is an argument to the test binary, and not to cargo,
280
+ which is why the command is ` cargo test -- --ignored ` .
281
+
222
282
# The ` tests ` module
223
283
224
284
There is one way in which our existing example is not idiomatic: it's
0 commit comments