Tips #

In this section we present a number of tips that we have collected over the course of using MockK in the real world.

Chains
Exclude
Timeout
Timeouts #
Return `Unit`
Return Unit # When stubbing a function that returns nothing, MockK provides a few shortcuts. val logger = mockk<Logger>() every { logger.log(any()) } returns Unit every { logger.log(any()) } answers { Unit } every { logger.log(any()) } just Runs justRun { logger.log(any()) } just Runs is the nicest to use, since its shorter than returns and answers and additionally works with coEvery. coEvery { logger.log(any()) } just Runs
Buy Me a Coffee at ko-fi.com