tdd-kotlin

star 0

TDD patterns for Kotlin CA/FP projects using Kotest + MockK + Arrow-kt. Use when writing tests, designing test cases, or following the red-green-refactor cycle. Triggers on: test file creation, writing value object tests, use case tests with mocked repositories, controller tests, property-based testing, coEvery/coVerify patterns.

wakita181009 By wakita181009 schedule Updated 2/23/2026

name: tdd-kotlin description: > TDD patterns for Kotlin CA/FP projects using Kotest + MockK + Arrow-kt. Use when writing tests, designing test cases, or following the red-green-refactor cycle. Triggers on: test file creation, writing value object tests, use case tests with mocked repositories, controller tests, property-based testing, coEvery/coVerify patterns.

TDD for Kotlin CA/FP

Test Stack

Library Purpose
kotlin("test") @Test annotation
kotest-assertions-core shouldBe, shouldBeInstanceOf
kotest-assertions-arrow shouldBeRight(), shouldBeLeft()
kotest-property checkAll(Arb.xxx()) { }
mockk mockk<T>(), coEvery, coVerify
kotlinx-coroutines-test runTest { }

Layer Test Patterns

Layer Approach
Domain No mocks. checkAll for boundaries, shouldBeRight/shouldBeLeft for Either results
Application mockk<Repository>(), coEvery/coVerify, runTest {}
Presentation mockk<UseCase>(), test each HTTP status code via response.statusCode shouldBe ...
Infrastructure Integration tests only — requires test containers or H2

Key Assertions

result.shouldBeRight(expectedValue)           // assert Right with specific value
result.shouldBeLeft().shouldBeInstanceOf<E>() // assert Left type
error.message shouldContain "expected text"   // assert error message content

coVerify(exactly = 1) { repo.save(any()) }   // verify call count
coVerify(exactly = 0) { repo.save(any()) }   // verify NOT called

Test Naming

@Test
fun `of returns Left InvalidId when value is zero or negative`() = runTest { ... }

@Test
fun `execute returns Left FetchFailed when repository throws exception`() = runTest { ... }

For complete test skeletons per layer (domain/application/presentation): see references/test-patterns.md.

Install via CLI
npx skills add https://github.com/wakita181009/clean-architecture-kotlin --skill tdd-kotlin
Repository Details
star Stars 0
call_split Forks 0
navigation Branch main
article Path SKILL.md
More from Creator
wakita181009
wakita181009 Explore all skills →