Return Unit

When stubbing a function that returns nothing, MockK provides a few shortcuts.

  1. val logger = mockk<Logger>()
  2. every { logger.log(any()) } returns Unit
  3. every { logger.log(any()) } answers { Unit }
  4. every { logger.log(any()) } just Runs
  5. justRun { logger.log(any()) }

just Runs is the nicest to use, since its shorter than returns and answers and additionally works with coEvery.

  1. coEvery { logger.log(any()) } just Runs