8

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?

Paweł Krupiński
  • 1,406
  • 1
  • 14
  • 23
  • 1
    please share more info, like some code, build script. PS: Mockito is not the right library for Kotlin. use Mockk – sidgate Jun 05 '20 at 04:57

1 Answers1

5

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.

Boris Sukhinin
  • 110
  • 1
  • 7