The following basic JUnit 5 assertions are included in org.junit.jupiter.api.Assertions
.
assertTrue()
: Assert that condition is trueassertFalse()
: Assert that condition is falseassertNull()
: Assert that object is nullassertNotNull()
: Assert that object is not nullassertEquals()
: Assert that expected and actual are equalassertNotEquals()
: Assert that expected and actual are not equalassertArrayEquals()
: Assert that expected and actual arrays are equalsassertSame()
: Assert that expected and actual refer to the same objectassertNotSame()
: Assert that expected and actual do not refer to the same objectUsing these assertions, implement the tests below.
Write a test method that asserts that a string:
Write a test method that asserts that:
Write a method that asserts that a list:
Write a method that asserts that a map:
Write a method that asserts that a method:
There assertion methods available in JUnit 5 are good, but fairly limited. We may miss something more sophisticated when dealing with more complex data structures and when seeking to write concise and readable test code.
To overcome these limitations, third-party assertion libraries have been developed:
Pick a library, and learn what kind of interesting new assertion methods it offers. Discover how your library handles the basic assertions we can already do with JUnit 5.