unit-test-boundary-conditions
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
By giuseppe-trisciuoglio · 3,233 installs
npx skills add giuseppe-trisciuoglio/developer-kit --skill unit-test-boundary-conditions
Source repository · Upstream listing
Unit Testing Boundary Conditions and Edge Cases
Overview
Systematic patterns for testing boundary conditions, corner cases, and limit values in Java using JUnit 5. Covers numeric boundaries, string edge cases, collection states, floating point precision, date/time limits, and off by one scenarios.
When to Use
Numeric min/max limits, null/empty/whitespace inputs
Overflow/underflow validation, collection boundaries
Off by one errors, floating point precision
Instructions
1. Identify boundaries : List numeric limits (MIN VALUE, MAX VALUE, zero), string states (null, empty, whitespace), collection sizes (0, 1, many)
2. Apply parameterized tests : Use @ParameterizedTest with @ValueSource or @CsvSource for multiple boundary values
3. Test both sides of boundaries : Cover values just below, at, and just above each boundary
4. Run tests after adding each boundary category to catch issues early
5. Verify floating point precision : Use isCloseTo(expected, within(tolerance)) with AssertJ
6. Test collection states : Explicitly test empty (0), single (1), and many ( 1) element scenarios
7. Handle overflow/underflow : Use Math.addExact() and Math.subtractExact() to detect arithmetic overflow
8. Test date/time edges : Verify leap years, month boundaries, timezone transitions
9. Iterate based on failures : When a boundary test fails, analyze the error to discover additional untested boundaries; add test cases for the newly discovered edge conditions
Examples
Requires: junit jupiter , junit jupiter params , assertj core .
Integer Boundary Testing
String Boundary Testing
Collection Boundary Testing
Floating Point Boundary Testing
Date/Time Boundary Testing
Array Index Boundary Testing
Best Practices
Test at boundaries explicitly : don't rely on random testing
Test null and empty separately from valid inputs
Use parameterized tests for multiple boundary cases
Test both sides of boundaries (just below, at, just above)
Verify error messages for invalid boundary inputs
Document why specific boundaries matter for your domain
Test overflow/underflow for all numeric operations
Constraints and Warnings
Integer overflow : Use Math.addExact() to detect silent overflow
Floating point precision : Never use exact equality; always use tolerance based assertions
NaN behavior : NaN != NaN ; use Float.isNaN() or Double.isNaN()
Collection size limits : Be mindful of memory with large test collections
String encoding : Test with Unicode characters for internationalization
Date/time boundaries : Account for timezone transitions and daylight saving
Array indexing : Always test index 0, length 1, and out of bounds
References
[Integer.MIN VALUE/MAX VALUE](https://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html)
[Double.MIN VALUE/MAX VALUE](https://docs.oracle.com/javase/8/docs/api/java/lang/Double.html)
[AssertJ Floating Point](https://assertj.github.io/assertj core features highlight.html assertions on numbers)
[Boundary Value Analysis](https://en.wikipedia.org/wiki/Boundary value analysis)
[references/concurrent testing.md](references/concurrent testing.md) Thread safety patterns
[references/parameterized patterns.md](references/parameterized patterns.md) Off by one and parameterized examples