Skip to content

giuseppe-trisciuoglio/developer-kit / plugins/developer-kit-java/skills/unit-test-utility-methods

unit-test-utility-methods

Verified

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 utils, test helpers, helper functions, static methods, or verifying utility code correctness.

FileKindSize
SKILL.mdskill md7.1 KB
references/edge-cases.mdmarkdown3.0 KB
references/parameterized-tests.mdmarkdown1.8 KB

references/parameterized-tests.md

View on GitHub
# Parameterized Tests for Utility Methods

Use `@ParameterizedTest` for testing multiple similar inputs efficiently.

## ValueSource - Single Parameter

```java
@ParameterizedTest
@ValueSource(strings = {"", " ", "null", "  \t  "})
void shouldConsiderFalsyValuesAsEmpty(String input) {
    assertThat(StringUtils.isEmpty(input)).isTrue();
}
```

## CsvSource - Multiple Parameters

```java
@ParameterizedTest
@CsvSource({
    "hello, HELLO",
    "world, WORLD",
    "test, TEST",
    "123abc, 123ABC"
})
void shouldConvertToUpperCase(String input, String expected) {
    assertThat(StringUtils.toUpperCase(input)).isEqualTo(expected);
}
```

## CsvSource - Email Validation

```java
@ParameterizedTest
@CsvSource({
    "user@example.com, true",
    "test@domain.org, true",
    "invalid-email, false",
    '", false',
    "no-at-sign.com, false"
})
void shouldValidateEmailsCorrectly(String email, boolean expected) {
    assertThat(ValidatorUtils.isValidEmail(email)).isEqualTo(expected);
}
```

## MethodSource - Complex Objects

```java
static Stream<Arguments> stringTransformationCases() {
    return Stream.of(
        Arguments.of("hello", "hello-world", "hello-world"),
        Arguments.of("Hello World", "hello_world", "hello_world"),
        Arguments.of("Test@123", "test123", "test123")
    );
}

@ParameterizedTest
@MethodSource("stringTransformationCases")
void shouldTransformStringsCorrectly(String input, String separator, String expected) {
    assertThat(StringUtils.toSlug(input, separator)).isEqualTo(expected);
}
```

## Null and Empty Sources

```java
@ParameterizedTest
@NullSource
@EmptySource
void shouldHandleNullAndEmpty(String input) {
    assertThat(StringUtils.isBlank(input)).isTrue();
}

@ParameterizedTest
@NullAndEmptySource
void shouldHandleNullEmptyAndBlank(String input) {
    assertThat(StringUtils.isBlank(input)).isTrue();
}
```
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 321kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 321kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 321kUpdated Claude CodeCodexVerifiedInstall
skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.Stars: 197kUpdated Claude CodeCodexVerifiedInstall