testing

Automate Kotlin end-to-end tests with TestRuntime, Kafka, and Postgres.

1|1|Updated Apr 9, 2024
One-click install
npx skills add https://github.com/navikt/helved-utbetaling --skill testing-navikt
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: testing
Source: https://github.com/navikt/helved-utbetaling/tree/main/.agents/skills/testing
Command: npx skills add https://github.com/navikt/helved-utbetaling --skill testing-navikt

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Test patterns for helved-utbetaling — TestRuntime singleton, runTest with CoroutineDatasource context, DataSource.await polling, Testcontainers reuse, and hand-rolled fakes (no mocking framework). Triggers — write tests, test fails, TestRuntime, runTest, /testing.

Core Features & Use Cases

  • Wire up a TestRuntime singleton that wires Postgres, Kafka mocks, and a Ktor test server.
  • Enable deterministic coroutine-based tests with a CoroutineDatasource context for all DAO calls.
  • Provide hand-rolled fakes instead of mocking frameworks to keep tests in-process and fast.

Quick Start

Run tests for the testing app with the configured TestRuntime and observe deterministic fixtures.

Frequently Asked Questions about testing

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

FAQPage Schema
How do I set up deterministic Kotlin coroutine tests with a shared datasource context?

Deterministic Kotlin coroutine tests use a TestRuntime singleton with a CoroutineDatasource context, ensuring all DAO calls run consistently. This setup wires Postgres, Kafka mocks, and a Ktor test server for reliable execution.

What is the best way to test Postgres-backed DAOs and Kafka streams without a mocking framework?

Testing Postgres-backed DAOs and Kafka streams without a mocking framework is achieved using hand-rolled fakes. This keeps tests in-process and fast, coordinated by the TestRuntime singleton for deterministic verification.

How do I poll a datasource during a Kotlin runTest block until test data is ready?

Polling a datasource during a Kotlin runTest block uses the DataSource.await mechanism. This ensures coroutine-based tests wait for Postgres test data setup to complete before executing assertions.

Can I reuse Testcontainers for Postgres across multiple Kotlin test modules to speed up test runtimes?

Yes, Testcontainers reuse is supported for Postgres across multiple Kotlin test modules. The TestRuntime coordinates this reuse, enabling fast, environment-isolated end-to-end test workflows.

Why do my Kotlin coroutine tests fail when the test runtime does not isolate the environment properly?

Kotlin coroutine tests fail without proper environment isolation because the TestRuntime enforces requirements around runnable test scaffolding and consistent test naming. It captures realistic tokens and fakes to ensure deterministic verification.

Do I need hand-rolled fakes instead of mocking frameworks for in-process Kotlin test runtimes?

Yes, hand-rolled fakes replace mocking frameworks for in-process Kotlin test runtimes. This approach maintains fast execution speeds and deterministic behavior for end-to-end workflows across Kafka and Postgres components.