<dependency> <groupId>org.assertj</groupId> <artifactId>assertj-core</artifactId> <!-- use 2.6.0 for Java 7 projects --> <version>3.6.2</version> <scope>test</scope> </dependency>
静态导入assertj
importstatic org.assertj.core.api.Assertions.*; importstatic org.assertj.core.api.Assertions.assertThat; // main one
assertj用法
// basic assertions assertThat(frodo.getName()).isEqualTo("Frodo"); assertThat(frodo).isNotEqualTo(sauron); // chaining string specific assertions assertThat(frodo.getName()).startsWith("Fro") .endsWith("do") .isEqualToIgnoringCase("frodo"); // collection specific assertions (there are plenty more) // in the examples below fellowshipOfTheRing is a List<TolkienCharacter> assertThat(fellowshipOfTheRing).hasSize(9) .contains(frodo, sam) .doesNotContain(sauron);