Junior — Middle
Can you explain what the AssertJ library is and what it is used for in testing?
sobes.tech AI
Answer from AI
AssertJ is a library for writing convenient and readable assertions in Java tests. It is used to verify expected results in automated tests, providing a rich and expressive API that allows writing checks in a fluent interface style. This makes tests more understandable and maintainable compared to using standard assert.
Example of using AssertJ:
import static org.assertj.core.api.Assertions.*;
@Test
public void testList() {
List<String> list = Arrays.asList("apple", "banana", "cherry");
assertThat(list)
.isNotEmpty()
.hasSize(3)
.contains("banana")
.doesNotContain("orange");
}
Thus, AssertJ helps to write more expressive and readable tests, improving automation quality.