运行下面的测试时出现错误。
@ExtendWith(MockKExtension::class)
class SenderServiceTest {
@MockK
lateinit var kafkaService: KafkaService<KeyType, MessageType>
@Test
fun `Send message`() {
val key = KeyType()
val value = MessageType()
verify(kafkaService).send(key, value)
}
}
@Service
@ConditionalOnProperty(name = ["kafka.enabled"])
class KafkaService<K, V>(val producerFactory: ProducerFactory<K, V>, val names: KafkaNames) {
fun send(key: K, value: V) {
// some code to send the message.
}
}
错误是
org.mockito.exceptions.misusing.NotAMockException:
Argument passed to verify() is of type KafkaService and is not a mock!
Make sure you place the parenthesis correctly!
我不知道为什么它说模拟豆不是模拟豆。有人能帮忙弄清楚吗?
1条答案
按热度按时间sc4hvdpw1#
您在一个测试中使用了2个mocking框架。您需要使用验证属于您用于构造mock的框架。
在MockK指南中检查和验证:
莫奇托
MockK: