Preamble

JUnit 5 (Jupiter) fixes the expressiveness gaps I felt in JUnit 4: nested classes express context, parameterized tests encode tables of cases, and extensions replace brittle rules. I want Java tests to read as cleanly as pytest suites when I switch languages mid-week.


@Nested for structure

Group Given/When/Then or state-machine phases as inner classes. Each nested level can own @BeforeEach setup—mirroring pytest fixtures scoped to classes.


@ParameterizedTest and sources

@CsvSource, @ValueSource, and @MethodSource cover the same ground as @pytest.mark.parametrize. Readable tables in source beat copy-paste test methods.


Cross-language consistency

When Python and Java services share a domain, parallel test structure reduces cognitive load: nested contexts and parameter tables tell the same story on both sides.


Conclusion

Test layout is documentation. Two-Pointer Patterns on Arrays: Python and Java Side by Side applies two-pointer patterns in both languages—algorithm posts benefit from the same bilingual habit.