Lessons on testing Java code: unit tests with JUnit 5, coverage with JaCoCo, mutation testing with PIT, test doubles with Mockito, and TDD.
5 lessons
Stop reading printed output. Learn to set up JUnit 5, write tests that pass or fail on their own, test boundaries with a parameterized test, and avoid the pitfalls that make a green test lie.
A green build and a hundred percent line coverage still let a bug through. Learn what JaCoCo measures, how to read its report, how to enforce a rule, and what coverage can't tell you.
A fully covered, green test suite can still miss a one-symbol bug. PIT plants bugs on purpose and counts how many your tests notice. Learn to read the report and fix the survivors.
A service that calls a remote carrier is slow and flaky to test. Learn the five kinds of test double, how Mockito builds them, state versus interaction testing, and what not to mock.
Write the test first. Follow the red-green-refactor loop on a real rule, see why small steps keep mistakes cheap, and learn the practices and pitfalls that decide whether TDD helps.