My tests contain the following mock :

    @MockkBean
    lateinit var myService: MyService

@MockkBean is frompackage import com.ninjasquad.springmockk.MockkBean

When i run./gradlew aotTestClasesses I am getting error:

Caused by: java.lang.IllegalArgumentException: Failed to generate code for '[MockkDefinition@72f855b9 name = [null], typeToMock = com.myApp.MyService, extraInterfaces = set[[empty]], clear = AFTER]' with type ?

It may be problem with mockkbean dependency but I am wondering if there is any workaround for this from spring/graalvm side? Thanks Spring boot 3.1.3

Comment From: wilkinsona

Mockito isn't supported in native tests. Duplicates https://github.com/spring-projects/spring-boot/issues/32195.

Comment From: wilkinsona

Sorry, I misread @MockkBean as @MockBean.

There's no way for us to work around Mockk not supporting AOT and native. This will have to be addressed in Mockk.

Comment From: hadson172

@wilkinsona Any advices how to handle mocking beans in tests on graalvm ? Thanks

Comment From: wilkinsona

Personally, I wouldn't run tests that require mocking in a native image as I think the benefits are minimal at best and are outweighed by the time that it takes to build the image. If you want to test a native image, I would build the main native image and then exercise it with an approach that's closer to end-to-end testing.

If you have any further questions, please follow up on Stack Overflow or Gitter. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements.