
Testing Quarkus with Kotlin, JUnit and MockK.Private functions mocking / dynamic calls.Verification atLeast, atMost or exactly times.Mock relaxed for functions returning Unit.Spies, mockkStatic may not work on JDK 16+ InaccessibleObjectException/ IllegalAccessException: read more here.Inline functions cannot be mocked: see the discussion on this issue.(not sure after workaround if it is generally usable or not, please somebody report it) PowerMock needs a workaround to run together with MockK #79.Documentation can be found hereįrom version 1.13.0 MockK supports Kotlin 1.4 and higher Known issues quarkus-mockk adds support for mocking beans in Quarkus.
springmockk introduced in official Spring Boot Kotlin tutorial. Expected behavior and behavior verification. Academy describing MockK from the very basics of mocking up to description of all advanced features. If the library is reasonably popular, it is very likely that there is already a Kotlin alternative or companion library that will help you.Check the series of articles “Mocking is not rocket science” at Kt. However, you are probably not the first to have this happen. Java libraries can sometimes cause problems in Kotlin. The individual commits show the original code with the failed test, the fix with the alternate matcher, and the final mock setup in Kotlin syntax. You can check the full code in my GitHub repository. In order for this code to compile, you need to add the following imports: import org. The method I was trying to stub was expecting a non-null String as an argument: interface MyDependency doReturn "Hello, World!" The cause was the any() argument matcher in my code to set up the method stub: val myDependencyMock = Mockito. When I ran the test, it failed with a NullPointerException: I recently ran into such a problem when trying to mock a dependency with Mockito.
Unfortunately, it can sometimes cause problems when interacting with Java code or libraries. The null safety feature in Kotlin is great for preventing NullPointerExceptions that are thrown at runtime.