Hello, I'm trying to integrate Kotest with Spring...
# kotest
s
Hello, I'm trying to integrate Kotest with SpringBoot and SpringMockK for veryfing bean calls via
@SpykBean
, but cannot get it working. my setup looks roughly like this:
Copy code
@SpringBootTest
class SomeTestClass(
 [...]
) : FunSpec() {
    @SpykBean
    private lateinit var someService: SomeService

    init {
        test("some test") {
            [...]
            verify { someService.someMethod(someArg) } // ERROR here
        }
    }
}
Test breaks when hitting
verify
block with beginning of the stack trace looking as follows:
Copy code
java.lang.NoClassDefFoundError: io/mockk/ValueClassSupportKt
	at io.mockk.impl.instantiation.JvmMockFactoryHelper.toDescription$mockk(JvmMockFactoryHelper.kt:150)
	at io.mockk.impl.instantiation.JvmMockFactoryHelper$mockHandler$1.invocation(JvmMockFactoryHelper.kt:25)
	at io.mockk.proxy.jvm.advice.Interceptor.call(Interceptor.kt:21)
I tried using
MockKAnnotations.init()
,
@ExtendWith(MockKExtension::class)
, moving
@SpykBean
to companion object, but nothing helped. Have anyone had such issue or could think of a solution? Thanks in advance
e
is
someArg
a value class? IIRC there's issues with value classes in MockK still. The problem sounds unrelated to kotest
s
No,
someArg
is Java class coming from generated resources in my case, but looks like the issue is with spy object itself, not with passed arguments. Verifying no-args method call results in same issue. Example with simple Spring's bean:
Copy code
@RestController
class SomeController {
    @GetMapping("/test")
    fun something() = "something"
}
Copy code
@SpringBootTest
class SomeTestClass(
 [...]
) : FunSpec() {
    @SpykBean
    private lateinit var someController: SomeController

    init {
        test("some test") {
            [...]
            verify { someController.something() } // ERROR here
        }
    }
}
Taking a look at the spy property within test class and intercepted MockK call within debug looks as attached. Looks like issue on the MockK site, but this wasn't a case with JUnit, so not sure what I'm missing. (Hidden base package names in screenshots)
message has been deleted
message has been deleted
After some digging turned out issue was indeed on MockK's site, overriding transitive SpringMocK's MockK version to latest resolved the issue :)
337 Views