Building, testing and debugging in Java
You build projects with Maven and Gradle, write thorough tests with JUnit 5 and Mockito and trace bugs to their source with jdb and logs.
Level 201 · 18 lessons · 15 practice labs
Lessons
Build tools
- The Maven lifecycle and pom.xml
- Dependencies, scopes and dependency:tree
- Building the same project with Gradle
- An executable JAR and version info
- Short task: set up a two-module project
Testing
- JUnit 5: lifecycle, assertions and display names
- Parameterised tests
- Mocks and verification with Mockito
- Temporary folders and file-system tests
- Coverage reports and thresholds with JaCoCo
- Short task: change an untested legacy class safely
Debugging and logging
- Reading stack traces and cause chains
- Breakpoints and stepping with jdb
- Log levels with SLF4J and Logback
- Keeping secrets out of logs
- Static analysis: javac -Xlint and compiler warnings
- Short task: find the bug using only logs and the debugger
Capstone
- Capstone: an invoice calculator with tests and a coverage gate
Practice labs
- Adding a dependency and version to pom.xml: Add the JUnit 5 dependency with test scope to the project, set the Java version and show mvn test runs.
- Resolving a dependency conflict from the tree: Find the library arriving in two versions from the dependency:tree output, pin the version with dependencyManagement and clear the NoSuchMethodError.
- Setting up a two-module project and porting it to Gradle: Set up a Maven project with core and app modules, build the same structure with Gradle too and show both tools run the same tests.
- Producing an executable JAR: Add the configuration that writes the main class into the manifest and show it runs with java -jar.
- Reading version info from the build: Write the project version into a properties file through resource filtering and show version and build time for the --version option.
- A reproducible JAR including dependencies: Produce a single JAR containing all dependencies and show two separate builds give the same SHA-256 hash and conflicting resource files merge correctly.
- Writing the first JUnit tests for a discount method: Write JUnit 5 tests with readable names for a discount method covering boundary values and the exception case.
- Testing tax bands with a parameterised test: Test a tax band table with CsvSource and expose the hidden bug at a band boundary.
- Changing an untested legacy class safely: First surround a pricing class with undocumented behaviour with tests pinning its current behaviour, then make the requested change without breaking them.
- Testing file-writing code with a temp folder: Use TempDir to test the content of the file an exporter writes and its behaviour when overwriting an existing file.
- Mocking a notification service with Mockito: Mock the e-mail sender and verify it is called once on a successful order, never on a failed one, checking its argument with ArgumentCaptor.
- Setting up a coverage threshold gate with JaCoCo: Add JaCoCo to the build, write the rule that fails the build when branch coverage is under eighty per cent and pass the gate by testing the missing branches.
- Reading the root cause from a stack trace: Find the class and line of the real error from a stack trace with a nested Caused by chain and fix the bug.
- Setting log levels and masking secrets: Move System.out calls to SLF4J, set a level per package and show by test that passwords and tokens do not reach the log.
- Finding a bug with only logs and the debugger: Follow the logs and set breakpoints with jdb to find the faulty branch in a batch job that occasionally produces a wrong balance, fix it and clear the -Xlint warnings.
About this course
You build projects with Maven and Gradle, write thorough tests with JUnit 5 and Mockito and trace bugs to their source with jdb and logs.
What you will learn
- Build tools
- Testing
- Debugging and logging
- Capstone
Prerequisites
Finishing the level 101 courses of the same path, or knowing those topics, is enough.
Lab environment
Lessons run in your own Kali Linux terminal that opens in the browser. Nothing to install; the lab starts clean in every lesson.
Frequently asked questions
- Is this course right for my level?
- The course is at level 201; it assumes you know the topics of the lower-level courses.
- Is there anything to install?
- No. Every lesson runs in your own lab environment that opens in the browser.
- How do lessons work?
- Each lesson has 8 to 10 steps and a short quiz. Early steps show the command to type, later steps give less help; if two attempts fail, the solution opens.
- Can I try it for free?
- Yes. The first three lessons of every course are free.