问题描述
我不明白为什么这些测试可以正常工作(它不是真正的代码,但与我的课程相同):
class AClasstest {
private val dep: Dep = mockk()
private val testedClass = TestedClass(dep)
@Test
fun testMethod1() {
testedClass.method1();
verify(exactly = 1) { dep.method() }
}
@Test
fun testMethod2() {
testedClass.method2();
verify(exactly = 1) { dep.method() }
}
}
为什么测试通过而不重置模拟? Mockk 会自动重置模拟吗?
我希望 @BeforeEach
或 @AfterEach
方法调用 clearMocks
来清除模拟状态。
也许清除只是为了清除行为,而不是检查数据? 那么在这种情况下,为什么这些测试可以正常工作?
class AClasstest {
private val dep: Dep = mockk()
private val testedClass = TestedClass(dep)
@Test
fun testMethodonIllegalArgumentException() {
every { dep.method() } throws IllegalArgumentException()
assertThrows<IllegalArgumentException> { testedClass.method() }
}
@Test
fun testMethodonindexoutofboundsexception() {
every { dep.method() } throws indexoutofboundsexception()
assertThrows<indexoutofboundsexception> { testedClass.method() }
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)