Claude-skill-registry java-testing

install
source · Clone the upstream repo
git clone https://github.com/majiayu000/claude-skill-registry
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/java-testing" ~/.claude/skills/majiayu000-claude-skill-registry-java-testing && rm -rf "$T"
manifest: skills/data/java-testing/SKILL.md
source content

Java Testing

Guidelines for writing tests in Java projects using the Spock Framework and Groovy.

When to use this skill

  • Writing new tests
  • Reviewing test code
  • Setting up test infrastructure
  • Configuring Testcontainers
  • Mocking dependencies in Spring Boot tests
  • When asked to "improve test setup" or "run all tests and fix"

Skill Contents

Sections

Available Resources

📚 references/ - Detailed documentation


Quick Start

1. Test Structure

def "should do Y when X"() {
    given:
        // create test data
    when:
        // execute process
    then:
        // assert output
    where: // use test table if suited
}

2. Test Naming

  • Test files:
    <ClassName>Spec.groovy
  • Test methods:
    "should [expected behavior] when [condition]"

Key Patterns

PatternWhen to Use
Spock MockUnit tests without Spring context
@SpringBeanSpring integration tests with mocks
@ServiceConnectionTestcontainers database connection
InProcessServergRPC client/server testing
Data TablesMultiple test cases with same structure

Mocking Patterns

Unit Tests (No Spring)

class SomeSpec extends Specification {
    SomeInterface someInterface = Mock()

    def "test method"() {
        given:
            def underTest = new ClassUnderTest(someInterface)
        when:
            // call method
        then:
            1 * someInterface.someMethod("value") >> responseClass
    }
}

Spring Integration Tests

@SpringBootTest
class SomeSpec extends Specification {
    @SpringBean
    SomeInterface someInterface = Mock()

    def "test method"() {
        when:
            // call method
        then:
            1 * someInterface.someMethod(_) >> { throw new RuntimeException() }
    }
}

Persistence Testing

Use Testcontainers with

@ServiceConnection
for database tests:

@Configuration
class IntegrationTestConfiguration {
    @Bean
    @ServiceConnection
    PostgreSQLContainer<?> postgreSQLContainer() {
        return new PostgreSQLContainer<>("postgres:14-alpine")
                .withDatabaseName("test_db")
    }
}

References

ReferenceDescription
references/spock-patterns.mdAdvanced Spock patterns
references/testcontainers-setup.mdTestcontainers configuration
references/grpc-testing.mdgRPC test patterns

Related Rules

Related Skills

SkillPurpose
java-coverageJaCoCo test coverage
gradle-standardsTest dependency bundles
<!-- AUTO-GENERATED FILE - DO NOT EDIT DIRECTLY --> <!-- Source: bitsoex/ai-code-instructions → java/skills/java-testing/SKILL.md --> <!-- To modify, edit the source file and run the distribution workflow -->