Programming foundations

Stage 6 · Lesson 6 of 8

Tests with JUnit

Build and ship your first projects

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 repoFree
    Project Based Learning

    Community maintained · Beginner

    Follow one guided build in your language, then build your own without a guide

Keep handy

  • Free APIs that give a small project real data to work with

Also worth your time

Mark this stage as not done?