Provides edge case, corner case, boundary condition, and limit testing patterns for Java unit tests. Validates minimum/maximum values, null cases, empty collections, numeric overflow/underflow, floating-point precision, and off-by-one scenarios using JUnit 5 and AssertJ. Use when writing .java test files to ensure code handles limits, corner cases, and special inputs correctly.
Provides systematic patterns for testing boundary conditions, corner cases, and limit values in Java using JUnit 5 and AssertJ. It targets the inputs where defects cluster: numeric minimums and maximums, zero, null, empty and whitespace strings, empty and single-element collections, arithmetic overflow and underflow, floating-point precision, date/time edges, off-by-one errors, and array index limits. The recommended process starts by cataloguing the relevant boundaries, such as numeric limits like Integer.MIN_VALUE and MAX_VALUE, string states, and collection sizes of 0, 1, and many. Parameterized tests using @ParameterizedTest with @ValueSource or @CsvSource drive many boundary values through a single test, and each boundary is exercised on both sides: just below, at, and just above. Tests are run after each boundary category so issues surface early, and failures are used to discover further untested edges to cover. Concrete example suites are included for each category. Integer tests cover the full min/max range and use Math.addExact() and Math.subtractExact() to detect silent overflow and underflow via ArithmeticException. String tests reject empty and whitespace inputs and handle null, single characters, and very long strings. Collection tests explicitly cover empty, single, and large lists plus nulls inside collections. Floating-point tests avoid exact equality, instead asserting closeness with isCloseTo(expected, within(tolerance)), and verify special values like POSITIVE_INFINITY, NEGATIVE_INFINITY, and NaN. Date/time tests check LocalDate.MIN and MAX, leap-year handling, and invalid dates such as Feb 29 in a non-leap year. Array tests confirm first and last element access and expected ArrayIndexOutOfBoundsException on negative, out-of-range, and empty-array access. Intended for use when writing .java test files, it requires the junit-jupiter, junit-jupiter-params, and assertj-core dependencies. Emphasized best practices include testing null and empty separately from valid inputs, verifying error messages for invalid boundaries, documenting why each boundary matters for the domain, and never relying on random testing to reach edge cases.
JUnit 5 (junit-jupiter), JUnit's parameter support (junit-jupiter-params), and AssertJ (assertj-core).
Never with exact equality. Use AssertJ's tolerance-based isCloseTo(expected, within(tolerance)), and account for special values such as NaN, POSITIVE_INFINITY, and NEGATIVE_INFINITY.
By using Math.addExact() and Math.subtractExact(), which throw ArithmeticException on overflow or underflow instead of silently wrapping around.
Empty (0), single (1), and many (greater than 1) elements, plus collections that contain null values.
With parameterized tests using @ParameterizedTest and @ValueSource or @CsvSource, covering values just below, at, and just above each boundary.
Quick Setup:
.claude/skills/Repository
giuseppe-trisciuoglio/developer-kit