https://kotlinlang.org logo
#mockk
Title
# mockk
j

juliocbcotta

03/28/2023, 2:35 PM
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

Jacob

03/28/2023, 2:55 PM
Nope. MockK is great! 😀
j

juliocbcotta

03/28/2023, 2:55 PM
Maybe I should file a bug, but I noticed a bunch of issues without replies in the repository 😕
m

Mattia Tommasone

03/28/2023, 2:59 PM
do you have more specifics on cases where you find it flaky?
j

juliocbcotta

03/28/2023, 2:59 PM
not at the moment, I just rerun the CI job and it works 😛
Let me see if I can find anything
m

Mattia Tommasone

03/28/2023, 3:00 PM
well it still fits the definition of flaky 😅
t

Thierry Merven

03/28/2023, 6:17 PM
For me it works great even when running in parallel.
j

juliocbcotta

03/30/2023, 9:30 AM
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

picaso

06/07/2023, 3:29 AM
Running into the same issue.
110 Views