Writing kotlin tests
개인용 에이전트 스킬 모음집
npx -y skills add dungsil/skills --skill writing-kotlin-testsAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
2 things to look at
- 28 days oldThe repository was created 28 days ago. New is not bad, but a brand new repository carrying a familiar-sounding name is the shape a typosquat arrives in, and there has been no time for anyone else to find a problem with it.
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Write, improve, or review Kotlin tests with kotlin-test, MockK, Spring Boot, and Spring Data JPA across unit, integration, and E2E levels. Use only for Kotlin test work, including domain, use-case, entity, validation, repository, adapter, coroutine, HTTP API, nullability, or Kotlin test-level selection decisions.
SKILL.md
6.4 KB, as published. Nobody here has run it
Writing Kotlin Tests
Use this skill to choose the right test level first, then write compact contract-focused Kotlin tests.
Use kotlin.test APIs for test annotations and assertions. Use MockK when interaction matters. Do not use JUnit assertion or annotation APIs, Mockito, AssertJ, Hamcrest, Truth, or another assertion library unless an existing framework assertion requires it. For E2E JSON body checks, use jsonPath or parse JSON and assert fields with kotlin.test; Hamcrest matchers are allowed only inside an existing jsonPath assertion API.
Workflow
- Read the target code, nearby tests, build configuration, Kotlin version, platform, and source set before writing anything.
- Decide the lowest useful test level: unit, integration, or E2E.
- Load the matching reference only when needed:
- Unit tests: references/unit.md
- Integration tests: references/integration.md
- E2E tests: references/e2e.md
- Identify the public contract and add the smallest useful test set.
- Avoid duplicate coverage across levels.
- Put unit and integration tests in the module and source set that own the behavior.
- Run the narrowest relevant test command first, then broader tests when risk justifies it.
Test Levels
Choose the lowest useful level:
- Domain value object, entity helper, use-case branch, validation rule, coroutine transformation, repository adapter call shape: unit test.
- JPA entity mapping, repository query, transaction/lifecycle behavior, Spring bean wiring: integration test.
- HTTP route, serialization, security filter, controller-service-use-case-repository flow: E2E test.
Avoid duplicate coverage:
- If E2E verifies HTTP -> repository -> domain -> JSON, do not also assert every mapped domain field in adapter unit tests.
- Keep adapter unit tests only for adapter-specific policy, such as forcing
activeOnly = trueon repository calls. - Keep entity unit tests for pure helper contracts such as
isDeleted()andsetDeleted().
Dependencies
- Use the project's existing
kotlin-testintegration and test runner. Do not change runner adapters merely to replace source imports. - Import annotations and assertions from
kotlin.test, such asTest,BeforeTest,assertEquals,assertContentEquals,assertFailsWith,assertIs, andassertNotNull. - Use MockK, not Mockito, for mocks, stubs, spies, or interaction verification.
- Use
kotlinx-coroutines-testonly when coroutine timing, dispatchers, cancellation, or virtual time are part of the contract and the project already provides it or the test requires it.
Test Fixtures
- Use Gradle
java-test-fixturesonly when fixtures must be shared across modules; Kotlin fixtures belong undersrc/testFixtures/kotlin. - Prefer fixtures in the adapter module that owns the fixture type.
- App-level E2E or integration tests may depend on
testFixtures(project(":<adapter-module>"))when they need adapter-owned entity fixtures. - Do not create a separate fixture module for a single adapter's test data.
- Prefer small factory functions with named arguments and useful defaults over builders that only assign properties.
Common Structure
Keep tests flat when the class has one meaningful behavior surface. Split a large test class by behavior or public entry point instead of depending on JUnit-specific @Nested groups.
Place successful or valid cases first, then boundary cases, then invalid or exception cases.
Use @BeforeTest when multiple tests repeat the same setup. Keep shared preconditions in setup and behavior-specific values inside the test function.
Naming
- Prefer descriptive backtick function names when the repository permits them; otherwise follow its established
should...convention. - Korean backtick test names must end with
~해야 한다or~이어야 한다. - Use
shouldBeRejectedWhen...for invalid inputs when identifier-style names are required. - Use
shouldBeReturned...When...for getter or helper return behavior. - Use
shouldBeThrownWhen...for expected exception paths. - Always write E2E with uppercase
E2Ein class and file names, such asUserProfileE2ETest.
Assertions
- Prefer one action per test and assert only its observable result.
- Use structural equality or several focused
kotlin.testassertions when one action produces multiple observable properties. - Use
assertFailsWith<ExpectedException>for exception contracts. - Use
assertContentEqualsfor arrays and sequences whose ordered contents are the contract. - Avoid asserting exception messages unless the message is part of the public contract.
- Do not use JUnit assertions through fully qualified calls or aliases.
Kotlin Nullability
Treat Kotlin types as the source of truth.
- Do not write
nulltests for non-null Kotlin parameters, properties, or return types; such calls are outside the Kotlin contract. - Cover
nullexplicitly for nullable types, including the policy encoded by the production code. - Do not use
null as T, reflection, or Java interop only to bypass the compiler unless Java-callable misuse defense is itself the public contract. - For Java platform types, make nullability explicit at the production boundary before testing internal behavior. Do not spread
!!into tests. - Keep test doubles and fixtures at least as strict as the production nullability contract.
Review Pass
Before finishing:
- Check the chosen test level is the lowest useful level.
- Check level-specific reference rules were followed.
- Check success cases appear before failure cases.
- Check imports use
kotlin.test, not JUnit test or assertion APIs. - Check MockK is used instead of Mockito and only where a fake would be less clear.
- Check tests cover the intended contract without duplicating higher-level coverage.
- Check
nulltests exist only for nullable contracts or explicit Java-interoperability misuse defense. - Check E2E class and file names use uppercase
E2E. - Check E2E JSON assertions target fields through
jsonPathor parsed JSON, not raw stringcontains. - Run the narrow test command and report the result.