Stage 6 · Lesson 6 of 8
Tests with JUnit
is the standard test for Java. Test classes live in src/test/java, and each test is a method marked with @Test. Assertions check the results, such as assertEquals(42.5, ledger.monthlyTotal(), 0.001).
The third argument there is a tolerance, a small allowed difference, because doubles (decimal numbers) are rarely exact. assertThrows(IllegalArgumentException.class, () -> parse("abc")) checks that bad input is rejected. @ParameterizedTest with @CsvSource runs one test over many inputs.
or Gradle runs them all with one command. Test the core logic, with no files or network inside, and cover such as an empty list and invalid values. Name tests after behaviour, such as rejectsNegativeAmounts, so a failure explains itself.
A question to check yourself, an AI practice session and 2 cheat sheet entries come when you add the roadmap to your account. Add it
Resources for this stage
Start with
- GitHub repoFreeProject Based Learning
Community maintained · Beginner
Follow one guided build in your language, then build your own without a guide
Keep handy
Also worth your time
How to present each project: the problem, stack, challenges and results
- Build Your Own XGo deeper
When you want a harder build: a shell, a key-value store or a tiny Git, from scratch