unit-test-utility-methods
Provides patterns for testing utility classes, static methods, and helper functions. Validates pure functions, null handling, edge cases, and boundary conditions. Generates AssertJ assertions and @ParameterizedTest for string utils, math utils, validators, and collection helpers. Use when testing ut
By giuseppe-trisciuoglio · 2,919 installs
npx skills add giuseppe-trisciuoglio/developer-kit --skill unit-test-utility-methods
Source repository · Upstream listing
Unit Testing Utility Classes and Static Methods
Overview
This skill generates tests for utility classes with static helper methods and pure functions. It provides patterns for testing null handling, edge cases, boundary conditions, and common utilities like string manipulation, calculations, data validation, and collections. Pure functions require no mocking.
When to Use
Use this skill when:
Writing tests for utility/helper classes with static methods
Testing pure functions with no state or side effects
Testing string manipulation, formatting, or transformation utilities
Testing calculation, conversion, or math helper functions
Testing data validation and formatter utilities
Verifying null/empty input handling in utility code
Testing collections or array helper methods
Instructions
1. Create test class : Name it after the utility (e.g., StringUtilsTest )
2. Test happy path : Valid inputs with expected outputs
3. Test edge cases : null, empty, whitespace, single elements
4. Test boundary conditions : max/min values, large numbers, precision
5. Use descriptive names : shouldCapitalizeFirstLetter instead of test1
6. Use AssertJ : For readable, chainable assertions
7. Use @ParameterizedTest : For multiple similar inputs (see references/parameterized tests.md )
8. Avoid mocking : Pure utilities need no mocks
Examples
Basic Static Utility Test
Comprehensive Example: isEmpty Implementation
Null Safe Utility
Math/Calculation Utility
Collection Utility
Data Validation Utility
Utility with Clock Dependency (Rare)
Best Practices
Test pure functions exclusively no side effects or state dependency
Cover happy path and edge cases null, empty, whitespace, extreme values
Use descriptive test names shouldReturnNullWhenInputIsNull
Use @ParameterizedTest for multiple similar inputs (see references/parameterized tests.md )
Test boundary conditions min/max values, overflow, precision
Avoid mocking pure functions only mock external dependencies like Clock
Keep tests independent no order dependency between tests
Constraints and Warnings
No mocking static methods : Use reflection utilities only when absolutely necessary
Pure function requirement : Stateful utilities are harder to test; prefer immutability
Floating point precision : Never use exact equality; use isCloseTo(delta)
Null handling consistency : Decide whether utility returns null or throws; test accordingly
Thread safety : Static utilities must be thread safe; verify concurrent behavior separately
Immutable inputs : Document whether utilities modify input parameters
Edge cases reference : See references/edge cases.md for boundary testing patterns