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.
If you have any questions, please use the AssertJ google group.
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 example shows an incorrect AssertJ API usage:
// BAD USAGE : DON'T DO THIS ! It does not assert anything assertThat(a1.equals(b1)); assertThat(a2.equals(b2)); assertThat(a3.equals(b3)); // DO THIS : assertThat(a1).isEqualTo(b1); assertThat(a2).isEqualTo(b2); assertThat(a3).isEqualTo(b3); // OR THIS (less classy but ok): assertThat(a1.equals(b1)).isTrue(); assertThat(a2.equals(b2)).isTrue(); assertThat(a3.equals(b3)).isTrue();
FindBugs can now detect such problems thanks to the CheckReturnValue annotation introduced in 2.5.+ / 3.5.+.
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.