hey, Do you folks find mockk flaky ? I migrated a ...
# mockk
j
hey, Do you folks find mockk flaky ? I migrated a bunch of tests to mockk and now I have it failing randomly in the CI...
j
Nope. MockK is great! 😀
j
Maybe I should file a bug, but I noticed a bunch of issues without replies in the repository 😕
m
do you have more specifics on cases where you find it flaky?
j
not at the moment, I just rerun the CI job and it works 😛
Let me see if I can find anything
m
well it still fits the definition of flaky 😅
t
For me it works great even when running in parallel.
j
this kind of error happens to me
Copy code
com.veepee.promotions.presentation.PromotionViewModelTest > promo code not valid FAILED
    io.mockk.MockKException at PromotionViewModelTest.kt:173
        Caused by: io.mockk.proxy.MockKAgentException at PromotionViewModelTest.kt:173
The test file doesn't have 173 lines 😭 and this is the test method... It doesn't seems to be very well written, but I don't understand how that exception happens
Copy code
@Test
    fun `promo code not valid`() {
        every { applyPromoCodeUseCase.applyPromoCode(any()) } returns Observable.just(
            Either.Failure(
                PromotionException.PromoCodeNotValid
            )
        )

        val observer = mockk<Observer<PromotionViewState>>()

        val slot = slot<PromotionViewState>()

        val list = arrayListOf<PromotionViewState>()

        promotionViewModel.viewState.observeForever(observer)

        every { observer.onChanged(capture(slot)) } answers {
            list.add(slot.captured)
        }

        promotionViewModel.applyPromoCode("notValidCode")
        assertEquals(list[0], PromotionViewState.Loading)
        assertEquals(list[1], PromotionViewState.ErrorNotValidPromoCode(emptyList()))

        promotionViewModel.viewState.removeObserver(observer)
    }
Any ideas?
p
Running into the same issue.
165 Views