kotlin-tdd

Structure Kotlin tests with fakes, Object Mothers, and TestClock.

14|2|Updated Sep 10, 2022
One-click install
npx skills add https://github.com/anderssv/the-example --skill kotlin-tdd
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-tdd
Source: https://github.com/anderssv/the-example/tree/main/skills/testing/kotlin-tdd
Command: npx skills add https://github.com/anderssv/the-example --skill kotlin-tdd

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It solves the problem of brittle, flaky Kotlin tests by guiding you to set up state predictably with fakes and to drive scenarios through domain behavior instead of direct data manipulation.

Core Features & Use Cases

  • Frictionless, readable test setup: Use extension functions on companion objects (Object Mother style) and .copy() to create consistent domain state quickly.
  • Fakes instead of mocks: Prefer HashMap-based fakes that behave like real implementations, enabling state-based assertions without mocking frameworks.
  • Testing Through The Domain (TTTD): Populate and verify system state via domain operations (e.g., register/approve flows) so tests survive domain evolution.
  • Controlled time: Use a TestClock to deterministically test time-based behavior like expiration and scheduling.
  • SystemTestContext dependency injection: Inject a central test context with fakes for repositories and clients to keep test wiring simple and repeatable.

Real-world use cases include writing stable TDD-style test scaffolding for service workflows, verifying end-to-end-ish outcomes across domain operations with in-memory fakes, and testing time-dependent rules without waiting in real time.

Quick Start

Ask Claude to help you write a Kotlin test using SystemTestContext with fakes, create domain input with valid() Object Mothers, control time with TestClock if needed, and verify outcomes via domain operations (TTTD) instead of repository state setup.

Frequently Asked Questions about kotlin-tdd

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write reliable Kotlin tests that don't become flaky?

Fakes behave like real implementations using HashMap-based state, enabling state-based assertions without mocking frameworks. This keeps tests deterministic and readable while verifying outcomes through actual domain behavior rather than framework interactions.

What is Testing Through The Domain and how does it improve TDD?

Testing Through The Domain (TTTD) populates and verifies system state via domain operations like register and approve flows instead of direct data manipulation. This makes tests survive domain evolution by driving scenarios through actual behavior rather than direct repository state setup.

How do I test time-dependent Kotlin logic without flaky delays?

Use a TestClock to deterministically test time-based behavior like expiration and scheduling without real-time delays. Inject it through SystemTestContext to control time progression in your Kotlin tests and verify time-dependent rules predictably.

Fakes vs mocks in Kotlin testing: which approach is better for TDD?

Fakes are preferred over mocks for Kotlin TDD because HashMap-based fakes behave like real implementations and enable state-based assertions without mocking frameworks. This approach supports end-to-end-ish outcome verification across domain operations with deterministic in-memory behavior.

When should I use real implementations versus fakes in Kotlin tests?

Use real implementations for domain logic that benefits from end-to-end verification, but switch to in-memory fakes for external repositories and clients. Inject fakes through SystemTestContext when testing service workflows requiring predictable state setup and controllable dependencies like TestClock.