Как тестировать с AssertJ?

Junior
313 просмотров
AFK Offer AI

AssertJ — fluent assertions, читабельнее JUnit. assertThat(list).hasSize(3).contains("a", "b").doesNotContain("x"). assertThat(user.getName()).isEqualTo("John").startsWith("Jo"). assertThat(exception).isInstanceOf(IllegalArgumentException.class).hasMessageContaining("invalid"). assertThat(list).extracting(User::getName).containsExactly("Alice", "Bob"). Soft assertions — проверить всё и показать все ошибки: SoftAssertions.assertSoftly(soft -> { soft.assertThat(...); }). assertThatThrownBy(() -> ...).isInstanceOf(...).

Следующий вопрос

Как написать хорошие интеграционные тесты в Spring Boot?