问题描述
我使用以下方法创建了一些模拟:val someService = mockk<SomeService>(relaxed = true)
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
MockK当前是否有一种方法可以做到这一点?
Is there currently a way to do this in MockK?
我知道这里有MockKAnnotations.init(this),但看起来好像没有办法在@Mock注释中设置relaxed = true
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
推荐答案
要在MockK中重置模拟,可以使用clearMocks
.要通过注释创建轻松的模拟,只需检查@RelaxedMockK
For resetting mocks in MockK you can use clearMocks
. To create relaxed mock via annotation just check @RelaxedMockK
这篇关于MockK-为每个测试重新初始化模拟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!