From ai-toolkit
Provides testing patterns for Micronaut/Kotlin backends: integration tests with Retrofit clients, repository tests, MockK rules, test naming, and coverage requirements. Use when writing tests, setting up infrastructure, or improving coverage.
How this skill is triggered — by the user, by Claude, or both
Slash command
/ai-toolkit:testing-strategiesThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
> See `integration-test-setup.md` for @MicronautTest configuration, Retrofit client setup, and connection pool tuning.
See
integration-test-setup.mdfor @MicronautTest configuration, Retrofit client setup, and connection pool tuning.See
examples.mdfor complete code patterns including MockK, test data builders, and assertions.
Every endpoint needs an integration test. Extend AbstractControllerTest, use Retrofit clients from module-client, and clean up with truncateAllTables() in @AfterEach.
Key rules:
HttpRequestaccessToken()@Test
fun `{action} - {expected outcome}`() = runBlocking { }
// Examples:
fun `getEmployee - returns employee by id`() = runBlocking { }
fun `getEmployee - returns 404 when not found`() = runBlocking { }
fun `createEmployee - fails with 401 when not authenticated`() = runBlocking { }
@Test
fun `getById - returns 404 when not found`() = runBlocking {
val token = accessToken(prepareUser())
assertThrows<HttpException> {
runBlocking {
client.getById(authorization = token, id = UUID.randomUUID())
}
}.also {
assertThat(it.code()).isEqualTo(404)
}
}
Extend AbstractRepositoryTest. Every repository needs these tests at minimum:
class DefaultEmployeeRepositoryTest : AbstractRepositoryTest() {
private val repository = DefaultEmployeeRepository(database)
@BeforeEach
fun cleanup() { database.primary.truncateAllTables() }
@Test
fun `insert - happy path`() { }
@Test
fun `byId - returns entity when exists`() { }
@Test
fun `byId - returns null when not exists`() { }
@Test
fun `byId - returns null when soft deleted`() { }
@Test
fun `deleteById - soft deletes entity`() { }
@Test
fun `update - updates selected fields`() { }
}
mockk<T>() for creating mockscoEvery / coVerify for suspend functions (not every/verify)slot<T>() + capture() to verify what arguments were passedrunTest { } from kotlinx.coroutines.test — NOT runBlocking. runTest handles virtual time and catches coroutine issues.// Given, // When, // Then@Nested + @DisplayName to group related testsSee
examples.mdfor full MockK code examples,@Nestedpatterns, test data builders, and AssertJ assertions.
Connection pool exhaustion: If parallel tests fail with "cannot acquire connection", bump maxPoolSize to 20. See integration-test-setup.md for the config snippet.
MockK + coroutines: Always use coEvery/coVerify for suspend functions. Plain every/verify won't work and gives confusing errors.
./gradlew test # All tests
./gradlew test --tests "com.yourcompany.EmployeeControllerTest" # One class
./gradlew :app:module-repository:test # One module
npx claudepluginhub c0x12c/ai-toolkit --plugin ai-toolkitProvides Kotlin testing patterns using Kotest, MockK, coroutine testing, property-based testing, and Kover coverage. Follows TDD methodology with idiomatic Kotlin practices.
Guides Kotlin TDD testing with Kotest specs, MockK mocking, coroutine/property-based tests, Ktor testApplication, and Kover coverage.
Guides writing and debugging TypeScript/NestJS unit tests with Jest, DeepMocked createMock, and in-memory databases. Activates on .spec.ts files or testing workflows.