-
Notifications
You must be signed in to change notification settings - Fork 41.3k
Description
Spring Boot provides @MockBean
and @SpyBean
annotations for integration tests, which create mock/spy beans using Mockito.
Even though Mockito is a fantastic mocking library, it's been written with Java in mind, and a long time ago. MockK is becoming a quite popular alternative for code written in Kotlin, and provides (IMHO) a cleaner and safer DSL than Mockito for Kotlin.
Although it's perfectly usable in Spring Boot tests already, Spring Boot doesn't provide equivalent annotations for MockK, and tests are thus a more cumbersome to write: beans must be manually defined using a @TestConfiguration
-annotated nested class, and care must be taken to reset the mocks after each test execution.
It would be nice if Spring Boot provided equivalent annotations for MockK, since Kotlin is a now a first-class citizen in Spring Boot.
The good news (or at least, I hope so)
I have created a SpringMockK library doing just that. The linked README describes the principle of the library (how it's been created), its limitations, and the differences with Mockito.
I would very much like that code to disappear from my repo and be integrated into Spring Boot.
Please tell if that would be possible, and how to proceed.
In addition to what the README contains, here is an additional useful indication: it's possible to mix Mockito tests and MockK tests in the the same project (which can be handy during a migration).