JUnit 5 course

A practical course from the first test class to a suite that covers a small application. Every lesson is a manual: a complete class under test, a complete test class, the two commands that compile and run them, and the report the launcher printed on the machine described at the end of the lesson. The course is written and published part by part: the cards below open the parts, and the tree lists the lessons that are ready to read.

The first part sets up the launcher and reads its report. Assertions come next, then the lifecycle that gives every test a fresh fixture, parameterised and repeated tests, exceptions and timeouts, temporary folders and files. The last parts organise a suite with tags and suites and build a task tracker whose tests are written one piece at a time.

Start with What JUnit 5 is and the launcher jar. For the shortest working example read Testing Java code with the JUnit launcher, and for the language itself open the Java hub.

@Test JUnit 5 course: Getting started The platform, the launcher jar, a first test, the report and a red test turned green. Open @Test JUnit 5 course: Assertions assertEquals and its delta, the boolean and null assertions, arrays and collections, and assertAll. Open @Test JUnit 5 course: Test classes and lifecycle Before and after every test and the class, @Disabled, @DisplayName, nested classes and one instance per class. Open @Test JUnit 5 course: Parameters and repeated tests Value, CSV, file, method and enum sources for parameterised tests, repeated tests and test factories. Open @Test JUnit 5 course: Exceptions, timeouts and assumptions assertThrows and assertDoesNotThrow, the two timeouts, assumptions and the exception that never comes. Open @Test JUnit 5 course: Test data and files A temporary folder per test, files in a test, a text format, an in-memory repository and hand-written fakes. Open @Test JUnit 5 course: Organising a test suite The test project layout, tags and filters, a suite of classes, parallel execution and the report a script reads. Open @Test JUnit 5 course: JUnit 5 in practice A calculator, a generic stack, text and Unicode, a service with a fake and a capstone task tracker. Open

All articles