Part 5 · 1 chapters · ~8 min
Tooling and Testing
Gradle and Maven with wrappers, JUnit 5 parameterised and nested tests, AssertJ and Mockito, Spring Boot test slices, Testcontainers with service connections, ArchUnit, Error Prone and Spotless, JaCoCo coverage, and dependency vulnerability scanning.
8
Build and test
code
@ParameterizedTest
@CsvSource({ "100000, 1000", "5000000, 25000" })
void fee(long amount, long expected) { assertThat(Fees.fee(amount)).isEqualTo(expected); }
@SpringBootTest @Testcontainers
class TransferApiTest {
@Container @ServiceConnection static PostgreSQLContainer<?> pg = new PostgreSQLContainer<>("postgres:17");
@Autowired TestRestTemplate http;
@Test void retriedTransferPostsOnce() {
var h = new HttpHeaders(); h.set("Idempotency-Key", "k1");
http.postForEntity("/v1/transfers", new HttpEntity<>(body, h), String.class);
http.postForEntity("/v1/transfers", new HttpEntity<>(body, h), String.class);
assertThat(balance("b")).isEqualTo(500);
}
}THE JAVA TOOLCHAIN
build, test and analyse
swipe the figure sideways, or tap expand for full screen
1/6
builds
Use the wrapper scripts (gradlew, mvnw) committed to the repo so every machine uses the same build tool version.
wrappers pin the tool versiondependency locking for reproducibility