Why is mocking so slow to start in Kotlin?

Viewed 886

Can anyone tell me why mocking "startup" is so slow in Kotlin?

The first test that uses mocks takes seconds (2-3 with mockk and 1-2 with Mockito). The rest take milliseconds.

There is no such overhead in Java with Mockito.

Way to reproduce: Write two tests (can be two methods in the same test class) using mockk. First test that creates mocks using mockk takes 2-5s, the next one will run in milliseconds. Compile and with IntelliJ or Gradle, the effect is the same.

Does anyone else have this problem?

1 Answers

We've experienced exactly the same problem: slow startup times with mockk. It seems the problem is with ByteBuddy library that mockk uses under the hood: https://github.com/mockk/mockk/issues/262#issuecomment-468334044

Just confirmed that the issue is still there in the latest mockk 1.10.2. Had to go with mockito and mockito-kotlin because of that.

Related