@@ -352,10 +352,21 @@ Naturally, legacy tests based on the JUnit 4 programming model can continue usin
352
352
[[writing-tests-assumptions]]
353
353
=== Assumptions
354
354
355
- JUnit Jupiter comes with a subset of the assumption methods that JUnit 4 provides and
355
+ Assumptions are typically used whenever it does not make sense to continue execution of a
356
+ given test — for example, if the test depends on something that does not exist in the
357
+ current runtime environment.
358
+
359
+ * When an assumption is valid, the assumption method does not throw an exception, and
360
+ execution of the test continues as usual.
361
+ * When an assumption is invalid, the assumption method throws an exception of type
362
+ `org.opentest4j.TestAbortedException` to signal that the test should be aborted instead
363
+ of marked as a failure.
364
+
365
+ JUnit Jupiter comes with a subset of the _assumption_ methods that JUnit 4 provides and
356
366
adds a few that lend themselves well to being used with Java 8 lambda expressions and
357
- method references. All JUnit Jupiter assumptions are static methods in the
358
- `{Assumptions}` class.
367
+ method references.
368
+
369
+ All JUnit Jupiter assumptions are static methods in the `{Assumptions}` class.
359
370
360
371
[source,java,indent=0]
361
372
----
@@ -371,7 +382,8 @@ to signal that a test should be aborted instead of marked as a failure.
371
382
372
383
JUnit Jupiter provides robust support for handling test exceptions. This includes the
373
384
built-in mechanisms for managing test failures due to exceptions, the role of exceptions
374
- in implementing assertions, and how to specifically assert non-throwing conditions in code.
385
+ in implementing assertions and assumptions, and how to specifically assert non-throwing
386
+ conditions in code.
375
387
376
388
[[writing-tests-exceptions-uncaught]]
377
389
==== Uncaught Exceptions
@@ -380,6 +392,16 @@ In JUnit Jupiter, if an exception is thrown from a test method, a lifecycle meth
380
392
extension and not caught within that test method, lifecycle method, or extension, the
381
393
framework will mark the test or test class as failed.
382
394
395
+ [TIP]
396
+ ====
397
+ Failed assumptions deviate from this general rule.
398
+
399
+ In contrast to failed assertions, failed assumptions do not result in a test failure;
400
+ rather, a failed assumption results in a test being aborted.
401
+
402
+ See <<writing-tests-assumptions>> for further details and examples.
403
+ ====
404
+
383
405
In the following example, the `failsDueToUncaughtException()` method throws an
384
406
`ArithmeticException`. Since the exception is not caught within the test method, JUnit
385
407
Jupiter will mark the test as failed.
0 commit comments