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.
In more detail
Test code uses static imports so assertions read fluently. Use them sparingly in production code, where the class name often helps the reader.
Example
import static org.assertj.core.api.Assertions.assertThat;Related terms
- import statement — A statement that makes code from another module or package available by name in the current file.
- AssertJ — A Java library of fluent assertions, starting with assertThat, that read like sentences and explain failures in detail.
Taught in
- Testing Basics With JUnit 5 — Modern Java: Virtual Threads & High-Throughput Services
- Fluent Assertions With AssertJ — Modern Java: Virtual Threads & High-Throughput Services