@@ -513,33 +513,22 @@ include::{kotlinTestDir}/example/KotlinAssertionsDemo.kt[tags=user_guide]
513513==== Third-party Assertion Libraries
514514
515515Even though the assertion facilities provided by JUnit Jupiter are sufficient for many
516- testing scenarios, there are times when more power and additional functionality such as
517- _matchers_ are desired or required. In such cases, the JUnit team recommends the use of
518- third-party assertion libraries such as {AssertJ}, {Hamcrest}, {Truth}, etc. Developers
519- are therefore free to use the assertion library of their choice.
516+ testing scenarios, there are times when more power and additional functionality are
517+ desired or required. In such cases, the JUnit team recommends the use of third-party
518+ assertion libraries such as {AssertJ}, {Hamcrest}, {Truth}, etc. Developers are therefore
519+ free to use the assertion library of their choice.
520520
521- For example, the combination of _matchers_ and a fluent API can be used to make
522- assertions more descriptive and readable. However, JUnit Jupiter's `{Assertions}` class
523- does not provide an
524- https://junit.org/junit4/javadoc/latest/org/junit/Assert.html#assertThat[`assertThat()`]
525- method like the one found in JUnit 4's `org.junit.Assert` class which accepts a Hamcrest
526- https://junit.org/junit4/javadoc/latest/org/hamcrest/Matcher.html[`Matcher`]. Instead,
527- developers are encouraged to use the built-in support for matchers provided by third-party
528- assertion libraries.
529-
530- The following example demonstrates how to use the `assertThat()` support from Hamcrest in
531- a JUnit Jupiter test. As long as the Hamcrest library has been added to the classpath,
532- you can statically import methods such as `assertThat()`, `is()`, and `equalTo()` and
533- then use them in tests like in the `assertWithHamcrestMatcher()` method below.
521+ For example, the following demonstrates how to use the `assertThat()` support from AssertJ
522+ in a JUnit Jupiter test. As long as the AssertJ library has been added to the classpath,
523+ you can statically import methods such as `assertThat()`, `assertThatException()`, etc.
524+ from `org.assertj.core.api.Assertions` and then use them in tests like in the
525+ `assertWithAssertJ()` method below.
534526
535527[source,java,indent=0]
536528----
537- include::{testDir}/example/HamcrestAssertionsDemo .java[tags=user_guide]
529+ include::{testDir}/example/AssertJAssertionsDemo .java[tags=user_guide]
538530----
539531
540- Naturally, legacy tests based on the JUnit 4 programming model can continue using
541- `org.junit.Assert#assertThat`.
542-
543532[TIP]
544533.Excluding Jupiter’s Assertions From a Project’s Classpath
545534====
@@ -594,6 +583,11 @@ NOTE: It is also possible to use methods from JUnit 4's `org.junit.Assume` class
594583assumptions. Specifically, JUnit Jupiter supports JUnit 4's `AssumptionViolatedException`
595584to signal that a test should be aborted instead of marked as a failure.
596585
586+ TIP: If you use AssertJ for assertions, you may also wish to use AssertJ for assumptions.
587+ To do so, you can statically import the `assumeThat()` method from
588+ `org.assertj.core.api.Assumptions` and then use AssertJ's fluent API to specify your
589+ assumptions.
590+
597591[[writing-tests-exceptions]]
598592=== Exception Handling
599593
0 commit comments