Test-driven development: JUnit



Expected Exceptions Test


BlockJUnit4ClassRunner – default junit runner
SpringJUnit4ClassRunner allows you to use dependency injection in test classes or to create transactional test methods.
MockitoJUnitRunner for automatic mock initialization.

Parameters class

JUnit 5 – @ExtendWith

replace with


or your custom rule:

hamcrest – how to test lists

check if single element is in a collection

check if multiple elements are in a collection

check all elements in a collection with strict order

check all elements in a collection with any order

check if collection is empty

check if array is empty

check if Map is empty

check if Iterable is empty

check size of a collection

checking size of an iterable

check condition on every item


Leave a comment

Your email address will not be published. Required fields are marked *