AssertJ
A Java library of fluent assertions, starting with assertThat, that read like sentences and explain failures in detail.
In more detail
AssertJ assertions describe collections, strings and exceptions precisely, for example containsExactly checks both the elements and their order. When one fails, the message shows the expected and actual values and the difference. Use exact order only when the contract promises it.
Examples
assertThat(names).containsExactly("Ada", "Lin");In this course: Java needs it because the language has no pytest-style assertion rewriting. It pairs with JUnit, which runs the tests while AssertJ describes the checks.Related terms
- assertion — A check that a condition is true, which stops a test or program with a failure if it is false.
- JUnit — The standard testing framework for Java, which discovers methods marked @Test, runs them and reports each failure with the test's name.
- static import — An import that brings a class's static methods into scope so they can be called without the class name, such as assertThat.
Taught in
- The Toolchain: Gradle — Modern Java: Virtual Threads & High-Throughput Services
- Async With CompletableFuture — Modern Java: Virtual Threads & High-Throughput Services
- Fluent Assertions With AssertJ — Modern Java: Virtual Threads & High-Throughput Services
- Introducing pytest — Automated Testing, TDD & Quality Engineering