所以我有以下代码:
When("SMS with location update command is received") {
every {
context.getString(R.string.location_sms, any(), any(), any(), any())
} returns "loc"
mainServiceViewModel.handleSms(SmsMessage("123", "location"))
Then("SMS with location is sent to specified phone number") {
verify(exactly = 1) {
smsRepository.sendSms("+123", "loc")
}
}
}
When("motion is detected") {
Then("information SMS is sent to specified phone number") {
verify(exactly = 1) {
smsRepository.sendSms("+123", any())
}
}
}
问题在于,这两种情况都通过了,即使第二种情况没有采取任何行动。我预计第二种情况会失败,因为 sendSms 方法甚至没有被调用。
- 如何重置 smsRepository 验证计数?
- 如何在每个When案例之前重置该计数?