java-testing

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

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "java-testing" with this command: npx skills add bitsoex/bitso-java/bitsoex-bitso-java-java-testing

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

  • When to use this skill

  • Quick Start

  • Key Patterns

  • Mocking Patterns

  • Persistence Testing

  • References

  • Related Rules

  • Related Skills

Available Resources

📚 references/ - Detailed documentation

  • grpc testing

  • junit5 migration

  • spock patterns

  • test setup workflow

  • test utilities

  • testcontainers setup

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 }

  1. Test Naming
  • Test files: <ClassName>Spec.groovy

  • Test methods: "should [expected behavior] when [condition]"

Key Patterns

Pattern When to Use

Spock Mock Unit tests without Spring context

@SpringBean Spring integration tests with mocks

@ServiceConnection Testcontainers database connection

InProcessServer gRPC client/server testing

Data Tables Multiple 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

Reference Description

references/spock-patterns.md Advanced Spock patterns

references/testcontainers-setup.md Testcontainers configuration

references/grpc-testing.md gRPC test patterns

Related Rules

  • java-testing-guidelines - Full testing reference

  • java-flyway-migrations - Flyway for test schema

Related Skills

Skill Purpose

java-coverage JaCoCo test coverage

gradle-standards Test dependency bundles

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

gradle-standards

No summary provided by upstream source.

Repository SourceNeeds Review
General

java-coverage

No summary provided by upstream source.

Repository SourceNeeds Review
General

java-standards

No summary provided by upstream source.

Repository SourceNeeds Review