JUnit Tutorial with Examples.
JUnit 6 tutorial for Java unit testing with Maven: assertions, lifecycle, parameterized tests, tags, parallel runs and JUnit 4 migration, with real output.
Beginner
Start here — no prior experience needed
Your First JUnit 6 Test with Maven
Write and run your first JUnit 6 test with Maven: the pom.xml you need, real Surefire output, reading a failing test, and running a single test method.
JUnit Assertions and Reading Failure Messages
JUnit 6 assertions through their failure output: assertAll, assertIterableEquals, assertLinesMatch, lazy messages, and AssertJ's diffs for the same bug.
JUnit Lifecycle, Assumptions and Conditional Tests
How JUnit 6 creates test instances, PER_METHOD vs PER_CLASS, assumptions that skip instead of fail, and tests enabled by OS, JRE or environment variable.
Intermediate
For developers with core concepts down
JUnit Parameterized Tests Beyond the Basics
JUnit 6 parameterized tests in depth: @EnumSource, null/empty sources, CSV files, @FieldSource, argument aggregation, display names, @ParameterizedClass.
JUnit Tags, Filtering, Ordering and Suites
Run the right JUnit 6 tests from Maven: @Tag with Surefire groups and tag expressions, method ordering, junit-platform.properties and @Suite classes.
Advanced
Production-grade patterns for experienced engineers
JUnit Timeouts and Parallel Test Execution
JUnit 6 timeouts and parallel runs: @Timeout, assertTimeout vs assertTimeoutPreemptively, parallel config, a shared-state race and @ResourceLock.
Migrating from JUnit 4 to JUnit 6
Migrate JUnit 4 tests to JUnit 6 step by step: run both via the Vintage engine, convert rules and expected exceptions, and spot 5-to-6 breaking changes.
Also part of JUnit
Taught in other topics. Each link opens the lesson in its home topic.
Unit Testing with JUnit 5 and Mockito
Learn JUnit 5 and Mockito by running real tests: lifecycle, assertions, assertAll, parameterized tests, stubbing, verify and ArgumentCaptor.
Advanced Testing in Java
Advanced Java testing by running it: custom JUnit 5 extensions, nested and dynamic tests, Mockito spies and strict stubs, H2 and Testcontainers.
Gradle — Modern Java Build Tool
Learn Gradle, the fast and flexible Java build tool: Kotlin DSL build scripts, the wrapper, dependencies, tests, custom tasks and multi-project builds.
Building REST APIs with Spring Boot
Build a REST API with Spring Boot 3 and curl it: path variables, query params, JSON bodies, ResponseEntity status codes, headers, CORS and MockMvc.
Java Annotations: Custom Types and Meta-Information
Create custom annotations, understand retention policies and targets, and use reflection to read annotation metadata at runtime.