Get a Cool Unit Test Environment with Spek2 + MockK + JaCoCo
summary
Kotlin unit-test setup using Spek2 (an RSpec-like DSL on JUnit5) with MockK for mocking final classes, singletons and extension functions, and JaCoCo for coverage. Shows exact Gradle changes: apply the kotlin-open plugin, add the JUnit5 engine plus junit-vintage for JUnit4 coexistence, register the Spek2 engine, and create Gradle tasks that run tests and generate/merge JaCoCo multi-module HTML and XML reports. Includes demos of mocking a singleton and an extension function and verifies the coverage reports are produced correctly.
AI-written summary · about
chapters (11)
- 0:00Introduction
- 2:28Unit test challenges
- 4:55Kotlin test libraries
- 5:40MockK intro
- 10:02MockK pros/cons
- 12:38MockK for singletons
- 14:28Spek2 intro
- 17:44Spek2 vs JUnit4
- 19:19Test environment demo
- 21:59JaCoCo coverage
- 28:30Summary
related talks
49mTesting Kotlin at Scale: Spek
32mStructure Unit Testing with Spek
32mTesting with Kotlin
01h 29mIntro to unit testing coroutines with Kotest & MockK
41mTesting in Kotlin: The Holy Grail of Readability and Power
28mTesting Out Kotlin
38mThe state of code coverage for Kotlin
43mEffective Unit testing with Kotlin
