MockK - reinitialize mocks for each test

jc12 picture jc12 · Feb 20, 2018 · Viewed 7.3k times · Source

I have some mocks created using: val someService = mockk<SomeService>(relaxed = true)

There are multiple tests in the file and I want the mock to be reset for each test

Is there currently a way to do this in MockK?

I know there is MockKAnnotations.init(this), but it didn't look like there was a way to set relaxed = true in the @Mock annotation

Answer

oleksiyp picture oleksiyp · Feb 20, 2018

For resetting mocks in MockK you can use clearMocks. To create relaxed mock via annotation just check @RelaxedMockK