Instruction file imported from navikt/sokos-skattekort (
.github/instructions/testing.instructions.md). Copyright stays with the author.
Testing essentials
Framework: Kotest (never JUnit) + MockK. Default spec style is BehaviorSpec (Given/When/Then/And) with Norwegian scenario text — both for unit and integration tests. Use FunSpec only for trivial, purely technical unit tests.
For full patterns, examples, and MockK/matchers cheat sheets, invoke the kotest skill.
Hard rules
- Integration tests with DB → use a database test listener with TestContainers; clear state before loading fixtures in each
Given. - Integration tests with SFTP → use an SFTP test listener.
- Any test that reaches an external HTTP client with a circuit breaker →
beforeEach { CircuitBreakerManager.circuitBreaker.reset() }. - Mock HTTP clients for external service calls — never make real HTTP calls in tests.
- For suspend functions use
coEvery/coVerify; neverrunBlockinginside test blocks.
File conventions
- Test files:
src/test/kotlin/no/nav/sokos/skattekort/... - Unit and integration tests should follow the existing package structure under
src/test/kotlin/no/nav/sokos/skattekort/... - SQL fixtures:
src/test/resources/database/**
Coverage audit — do this before drawing conclusions
Before claiming that an area lacks tests, always run:
find src/test -type f -name "*.kt" | sort
- Never use
| heador limit output — test files live in subcategories (unit/,integration/,database/,client/,config/) and are easily truncated - Evaluate actual file content, not just file names, before concluding on scenario coverage
Boundaries
✅ Always
BehaviorSpecas default; Norwegian Given/When/Then text- Reset circuit breaker in
beforeEachfor tests reaching external services - Kotest matchers (
shouldBe,shouldHaveSize,shouldBeEmpty,with { ... })
🚫 Never
- JUnit
- Real HTTP calls to external services in tests
runBlockinginside test blocks- Leak mutable state between scenarios