You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've recently discovered that our tests are needlessly slow. By investigation I found out that the following pattern is slow.
class TestWithLateinitMockk
{
private lateinit var one: AtomicInteger
@BeforeEach
fun setup()
{
one = mockk()
every { one.get() } returns 1
}
@Test
fun testIt()
{
Assertions.assertEquals(3, 2 + one.get())
}
}
In contrary, I have three different Tests:
class BasicTest
{
private var one: AtomicInteger = AtomicInteger(1)
@Test
fun testIt()
{
Assertions.assertEquals(3, 2 + one.get())
}
}
class TestWithLateinit
{
private lateinit var one: AtomicInteger
@BeforeEach
fun setup()
{
one = AtomicInteger(1)
}
@Test
fun testIt()
{
Assertions.assertEquals(3, 2 + one.get())
}
}
class TestWithMockk
{
private var one: AtomicInteger = mockk()
@BeforeEach
fun setup()
{
every { one.get() } returns 1
}
@Test
fun testIt()
{
Assertions.assertEquals(3, 2 + one.get())
}
}
Each of those three tests run on my machine in low (one or two digits) milliseconds. The lateinit mockk tests needs more than one second for the same Assertion. So it's several orders of magnitude slower. (Please see the working code in my Gitlab Repository, so that you can try it yourself.)
I don't know if this is a bug. If not than maybe someone can explain to me, why lateinit mockks have such an impact on performance. I know that mock(k)ing is a bit slower due to reflection. But I don't understand the difference between initialize on declaration and late initialized mockks.
The text was updated successfully, but these errors were encountered:
I've recently discovered that our tests are needlessly slow. By investigation I found out that the following pattern is slow.
In contrary, I have three different Tests:
Each of those three tests run on my machine in low (one or two digits) milliseconds. The lateinit mockk tests needs more than one second for the same Assertion. So it's several orders of magnitude slower. (Please see the working code in my Gitlab Repository, so that you can try it yourself.)
I don't know if this is a bug. If not than maybe someone can explain to me, why lateinit mockks have such an impact on performance. I know that mock(k)ing is a bit slower due to reflection. But I don't understand the difference between initialize on declaration and late initialized mockks.
The text was updated successfully, but these errors were encountered: