tests

Guide Kotlin Spring WebFlux unit and integration tests with Truth assertions.

Updated Sep 2, 2024
One-click install
npx skills add https://github.com/IanArb/GymPlannerService --skill tests-ianarb
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: tests
Source: https://github.com/IanArb/GymPlannerService/tree/main/.claude/skills/tests
Command: npx skills add https://github.com/IanArb/GymPlannerService --skill tests-ianarb

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Provides standardized patterns and conventions for writing unit and integration tests in GymPlannerService, ensuring tests are consistent, maintainable, and fast.

Core Features & Use Cases

  • Two main testing approaches are described: controller tests (HTTP layer only) and service tests (business logic without Spring context). Controller tests use @WebFluxTest with Mockito, while service tests rely on MockK and direct instantiation.
  • Clear guidance on required annotations, mocking strategies, and naming conventions to enforce isolation and reliability across test suites.
  • Includes expectations for test structure, data provisioning, and assertion styles to promote consistency and quality across contributors.

Quick Start

Run the test suite with ./gradlew clean test to execute all integration and unit tests.

Frequently Asked Questions about tests

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

FAQPage Schema
How do I write unit tests for Kotlin Spring WebFlux controllers?

Service layer tests in Spring WebFlux use MockK for mocking and instantiate the service class directly. This strategy isolates business logic from the Spring context, ensuring tests remain fast, maintainable, and independent of framework overhead.

What assertion library should I use for Kotlin Spring integration tests?

Truth assertions are enforced for Kotlin Spring integration and unit tests. Using Truth promotes consistency across test suites and standardizes expectation styles, ensuring test quality and reliable isolation for all contributors.

How do I run all unit and integration tests for a Kotlin Spring project?

Execute the full test suite for a Kotlin Spring project using the Gradle command ./gradlew clean test. This runs all unit and integration tests, validating both the controller HTTP layer and the isolated service business logic.

Why use MockK instead of Mockito for Kotlin service layer tests?

MockK is used for service layer tests because it provides better Kotlin language support for direct class instantiation and mocking. Mockito is reserved for controller tests, separating HTTP layer mocking from business logic mocking strategies.

Does this testing pattern require a running Spring context for service tests?

Standardized testing patterns enforce required annotations, mocking strategies, and naming conventions for WebFlux microservices. This ensures test isolation, reliability, and consistent quality across different contributors working on the same Kotlin Spring project.