MockK - reinitialize mocks for each test

青春壹個敷衍的年華 提交于 2020-01-24 04:10:47

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/48894560/mockk-reinitialize-mocks-for-each-test

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!