test-suite-builder

작성자: kotlin

계층화된 Kotlin + Spring 테스트를 설계 및 생성하여 단위, 슬라이스, 통합 수준에서 속도, 현실성, 회귀 가치의 균형을 맞춥니다. 다음을 추가할 때 사용합니다…

npx skills add https://github.com/kotlin/kotlin-backend-agent-skills --skill test-suite-builder

Test Suite Builder

Source mapping: Tier 1 critical skill derived from Kotlin_Spring_Developer_Pipeline.md (SK-14).

Mission

Choose the lightest test that proves the behavior. Generate tests that catch regressions instead of reproducing the implementation line by line.

Start With A Test Strategy

Before writing code, classify what needs to be proven:

  • pure business logic
  • HTTP contract and validation
  • repository query behavior
  • serialization behavior
  • security rules
  • cross-component integration
  • database or message-broker integration

Three-Layer Strategy

  • Use unit tests for domain logic, calculations, decision tables, and deterministic branching.
  • Use slice tests for framework boundaries:
    • @WebMvcTest or WebTestClient for HTTP
    • @DataJpaTest for repositories
    • focused JSON or security slices when available in the project
  • Use @SpringBootTest and Testcontainers only when a realistic application graph or infrastructure boundary must be proven.

Kotlin Testing Rules

  • Prefer JUnit 5.
  • Prefer MockK over Mockito unless the repository already standardizes on something else.
  • Use readable backtick test names when that matches the project style.
  • Use runTest and the coroutine test toolkit for coroutine-heavy code.
  • Build reusable fixtures, builders, or object mothers instead of duplicating inline object construction.

What To Cover

  • Success path.
  • Validation failures.
  • Business rule failures.
  • Edge cases around nullability, optional fields, empty collections, and duplicates.
  • At least one regression-oriented test for the bug or change that motivated the work.

What Not To Do

  • Do not default to @SpringBootTest when a slice test or unit test is enough.
  • Do not write tests that only verify mock interactions and prove nothing observable.
  • Do not couple assertions to private implementation details when public behavior is enough.
  • Do not use real time, random values, or shared mutable state without control.

Output Contract

Return these sections:

  • Test plan: which layers to use and why.
  • Generated tests: the concrete test classes or patch plan.
  • Test data support: builders, fixtures, or factories to add.
  • Coverage gaps: important cases still not covered.
  • Verification: commands to run and which tests should fail before the fix.

Framework-Specific Checks

  • Match MockMvc vs WebTestClient to MVC vs WebFlux.
  • Match Testcontainers setup to the actual database or broker in the repository.
  • If serialization or validation is the bug, include a test that proves the wire contract, not only the service logic.
  • If transaction behavior matters, add a test that proves rollback or uniqueness behavior in the real persistence layer.

Advanced Testing Nuances

  • A transactional test that always rolls back can hide commit-time failures. Use explicit flush or real commit boundaries when unique constraints, triggers, or transaction listeners matter.
  • H2 is not a safe stand-in for Postgres or MySQL when dialect, JSON, locking, index use, or transaction semantics matter. Prefer the real engine with Testcontainers for those cases.
  • @MockBean is powerful but expensive. Overusing it turns integration tests into slow unit tests with hidden wiring.
  • Security tests should usually prove both 401 and 403, not just the happy authorized path.
  • Async and event-driven flows need deterministic waiting strategies such as controlled schedulers, latches, or Awaitility. Do not scatter sleeps.
  • Concurrency and deadlock behavior cannot be proven in a single-threaded rollback test. Use multiple transactions and explicit synchronization when reviewing those cases.
  • Reused containers improve speed but require strict state isolation. Do not trade determinism away for a faster green build.
  • Use deterministic time and ID providers when business logic depends on clocks or UUIDs.

Expert Heuristics

  • If a bug was caused by framework wiring, add at least one test above unit level.
  • If a bug was caused by domain branching, do not drag the whole Spring context into the fix.
  • When in doubt, choose the smallest test that would have failed before the change.
  • Treat test code as production code for readability and maintenance. Fixtures and helpers should reduce noise, not hide behavior.

Guardrails

  • Keep tests deterministic.
  • Keep setup explicit and local to the scenario.
  • Prefer one clear reason for failure per test.
  • Do not silently introduce slow infrastructure-heavy tests into fast unit test suites.

Quality Bar

A good run of this skill produces a test suite that is fast where possible and realistic where necessary. A bad run floods the project with context-heavy tests, brittle mocks, and no clear explanation of why each test level exists.

kotlin의 다른 스킬

kotlin-backend-jpa-entity-mapping
kotlin
Kotlin의 data class는 DTO에 자연스럽지만 JPA 엔티티에는 위험합니다. Hibernate는 data class가 깨뜨리는 identity 의미론에 의존합니다. 모든 필드에 대한 equals/hashCode는 상태 변경 후 Set/Map 멤버십을 손상시키고, 자동 생성된 copy()는 관리되는 엔티티의 분리된 복제본을 만듭니다.
kotlin-tooling-agp9-migration
kotlin
Android Gradle Plugin 9.0은 동일한 모듈에서 Android 애플리케이션 및 라이브러리 플러그인을 Kotlin Multiplatform 플러그인과 호환되지 않게 만듭니다. 이 스킬은 마이그레이션 과정을 안내합니다.
kotlin-tooling-cocoapods-spm-migration
kotlin
KMP 프로젝트를 CocoaPods(kotlin("native.cocoapods"))에서 Swift Package Manager(swiftPMDependencies DSL)로 마이그레이션 — pod()를 swiftPackage()로 대체,…
kotlin-tooling-immutable-collections-0-5-x-migration
kotlin
Kotlin(및 Java) 코드를 kotlinx.collections.immutable 0.3.x / 0.4.x에서 최신 0.5.x로 마이그레이션합니다. 0.5.x 라인은 모든 복사본을 반환하는 메서드의 이름을 변경합니다…
kotlin-tooling-java-to-kotlin
kotlin
Java 소스 파일을 체계적인 4단계 변환 방법론을 사용하여 관용적인 Kotlin으로 변환하며, 각 단계에서 5가지 불변 조건을 확인합니다. 애노테이션 사이트 대상, 라이브러리 관용구, API 보존을 처리하는 프레임워크 인식 변환을 지원합니다.
kotlin-tooling-native-build-performance
kotlin
Kotlin Multiplatform 프로젝트에서 iOS를 대상으로 할 때 느린 Kotlin/Native 컴파일 및 링크를 진단하고 수정합니다. 사용자가 느린 iOS 또는…을 보고할 때 사용하세요.
kotlin-spring-proxy-compatibility
kotlin
Diagnose and prevent Kotlin plus Spring proxy failures around `@Transactional`, `@Cacheable`, `@Async`, method security, retry, configuration proxies, and JPA…
ci-cd-containerization-advisor
kotlin
재현 가능한 빌드, 이미지 및 배포 파이프라인을 설계합니다. Kotlin 및 Spring 애플리케이션을 대상으로 하며, CI 검증, 계층형 컨테이너, 롤아웃 안전성 등을 포함합니다.