unit-testing-kotlin

Generate JUnit 5, MockK, or Kotest unit tests for Kotlin coroutines.

Updated Mar 5, 2026
One-click install
npx skills add https://github.com/Astrumon/Spovishun --skill unit-testing-kotlin
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: unit-testing-kotlin
Source: https://github.com/Astrumon/Spovishun/tree/main/.claude/skills/unit-testing-kotlin
Command: npx skills add https://github.com/Astrumon/Spovishun --skill unit-testing-kotlin

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps developers write clear, reliable unit tests for Kotlin codebases, reducing regressions and improving confidence when refactoring and adding features.

Core Features & Use Cases

  • Framework guidance: Provides idiomatic patterns and examples for JUnit 5, MockK, and Kotest.
  • Coroutine testing: Recommends runTest, coEvery/coVerify, and strategies for testing suspending functions and asynchronous behavior.
  • Project rules & structure: Promotes the Arrange-Act-Assert pattern, backtick test names, clearing mocks between tests, and avoiding real database connections in unit tests.
  • Use Case: Writing service and repository unit tests, implementing TDD for new features, and documenting expected behavior through tests.

Quick Start

Generate unit tests for UserService.findByTelegramId using JUnit 5, MockK, the AAA pattern, and runTest for suspending functions.

Frequently Asked Questions about unit-testing-kotlin

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

FAQPage Schema
How do I write unit tests for Kotlin coroutines using JUnit 5?

Unit tests for Kotlin coroutines should use the runTest builder alongside MockK's coEvery and coVerify to arrange and verify suspending functions, ensuring asynchronous behavior is validated correctly without blocking threads.

What is the best way to structure Kotlin unit tests for service layer logic?

The best way to structure Kotlin unit tests is using the Arrange-Act-Assert pattern with descriptive backtick test names, ensuring clear separation of setup, execution, and verification phases for service layer logic.

How do I mock repository interfaces in Kotlin unit tests without database connections?

Mock repository interfaces in Kotlin unit tests using MockK to provide fake implementations, ensuring you avoid real database connections and isolate the service layer logic being tested.

Does MockK work with Kotest for test-driven development in Kotlin?

MockK works seamlessly with Kotest for test-driven development, allowing you to mock dependencies and verify interactions while leveraging Kotest's expressive assertion library and testing styles.

Why should I clear mocks between Kotlin unit tests?

Clearing mocks between Kotlin unit tests using clearAllMocks prevents state leakage and test pollution, ensuring each test runs in isolation and produces reliable, repeatable results across the test suite.