assertj 는 junit이 기본 제공하는 API 보다 가독성이 좋다.
<dependency> <groupId>org.assertj</groupId> <artifactId>assertj-core</artifactId> <version>3.22.0</version> <scope>test</scope> </dependency>
요즘은 assertj를 사용하는 것이 대세라고 한다.
import static org.assertj.core.api.Assertions.assertThat; import org.junit.jupiter.api.Test; public class SimpleAssertionsExample { @Test void a_few_simple_assertions() { assertThat("The Lord of the Rings").isNotNull() .startsWith("The") .contains("Lord") .endsWith("Rings"); } }
@Test void basic_soft_assertions_example() { SoftAssertions softly = new SoftAssertions(); softly.assertThat("George Martin").isEqualTo("JRR Tolkien"); softly.assertThat(42).isGreaterThan(100); softly.assertThat("Gandalf").isEqualTo("Sauron"); // Don't forget to call assertAll() // otherwise no assertion errors are reported! softly.assertAll(); }