AssertJ core is a Java library that provides a fluent interface for writing assertions. Its main goal is to improve test code readability and make maintenance of tests easier.
AssertJ core provides assertions for JDK standard types and can be used with JUnit or TestNG.
Different AssertJ major versions depend on different Java versions :
Note that AssertJ 3.x includes all AssertJ 2.x features and adds Java 8 specific ones (like exception assertions with lambdas).
For a quick start, have a look at our one minute getting started guide.
Convert existing JUnit assertions to AssertJ ones : we have a guide to easily convert JUnit assertions to AssertJ.
You are more than welcome to raise an issue if you need new assertions or see potential improvements.
Although AssertJ Core can be used with Android, I suggest using AssertJ-Android, a useful extension specifically for Android.
AssertJ is a fork of FEST Assert, a great project I have contributed to for 3 years. So why did I fork it ?
There are two main reasons :
On the contrary AssertJs goal is to provide a rich set of assertions and any reasonable request to enrich AssertJ assertions is welcome. AssertJ is community driven, we listen to our users since AssertJ is built for them.
If you feel that some assertion is missing, please fill a ticket or even better make a contribution !Joel Costigliola (AssertJ creator)
Android does not support the java.nio.file.Path class, so the 'regular' AssertJ 3.x/2.x entry point classes can not be used. Instead you can use the Java6XAssertions classes. For example use org.assertj.core.api.Java6Assertions instead of org.assertj.core.api.Assertions.
The following listing contains 'regular' import statements and their android alternative:
// 'regular' assertj import static org.assertj.core.api.Assertions.* // assertj on android import static org.assertj.core.api.Java6Assertions.* // 'regular' assertj import static org.assertj.core.api.SoftAssertions.* // assertj on android import static org.assertj.core.api.Java6SoftAssertions.* // 'regular' assertj import static org.assertj.core.api.JUnitSoftAssertions.* // assertj on android import static org.assertj.core.api.Java6JUnitSoftAssertions.* // 'regular' assertj import static org.assertj.core.api.BDDAssertions.* // assertj on android import static org.assertj.core.api.Java6BDDAssertions.* // 'regular' assertj import static org.assertj.core.api.BDDSoftAssertions.* // assertj on android import static org.assertj.core.api.Java6BDDSoftAssertions.* // 'regular' assertj import static org.assertj.core.api.JUnitBDDSoftAssertions.* // assertj on android import static org.assertj.core.api.Java6JUnitBDDSoftAssertions.*
The following examples show incorrect AssertJ API usages:
// BAD USAGE : DON'T DO THIS ! It does not assert anything assertThat(actual.equals(expected)); // DO THIS : assertThat(actual).isEqualTo(expected); // OR THIS (less classy but ok): assertThat(actual.equals(expected)).isTrue(); // BAD USAGE : DON'T DO THIS ! describedAs has no effect assertThat(actual).isEqualTo(expected).describedAs("description"); // DO THIS : assertThat(actual).describedAs("description").isEqualTo(expected); // BAD USAGE : DON'T DO THIS ! Comparator is not used assertThat(actual).isEqualTo(expected).usingComparator(new CustomComparator()); // DO THIS : assertThat(actual).usingComparator(new CustomComparator()).isEqualTo("a");
Static code analysis tools like FindBugs can now detect such problems thanks to the CheckReturnValue annotation introduced in 2.5+ / 3.5+ and improved in 2.7+ / 3.7+.
AssertJ Core is hosted on github : https://github.com/joel-costigliola/assertj-core.
Please report bugs or missing features in the AssertJ Core issue tracker.
AssertJ's Vetinari (ok, maybe not as Machiavellian), enjoy playing basket ball, love Terry Pratchett's disc world (surprised ?), work with linux.
AssertJ collaborator, who loves books, history and books about history.
You are very welcome to contribute, we want to offer the richest and easiest to use assertion API, so ideas from our users are very appreciated.
Contributing is easy and we try to help people contributing. Have a look at the contributor guidelines (these are the same guidelines shown when you create a new issue).
Special thanks assertj-core contributors :
AssertJ has its roots in FEST Assert, a project I have contributed to for 3 years, so thanks to Alex Ruiz FEST's creator !
Thanks to SonarQube for providing AssertJ Core quality reports.