英文:
Argument passed to verify() is of type KafkaProducerService and is not a mock
问题
I get an error when running the below test.
@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.
}
}
The error is:
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!
I am not sure why it says the mock bean is not a mock. Someone can help to figure it out?
英文:
I get an error when running the below test.
@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.
}
}
The error is
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!
I am not sure why it says the mock bean is not a mock. Someone can help to figure it out?
答案1
得分: 1
You are using 2 mocking frameworks in one test.
You need to use verify belonging to framework you used to construct the mock.
Check verify in MockK guidebook:
Mockito
// Mockito
val mockedFile = mock(File::class.java)
mockedFile.read()
verify(mockedFile).read()
MockK:
// MockK
val mockedFile = mockk<File>()
mockedFile.read()
verify { mockedFile.read() }
英文:
You are using 2 mocking frameworks in one test.
You need to use verify belonging to framework you used to construct the mock.
Check verify in MockK guidebook:
Mockito
// Mockito
val mockedFile = mock(File::class.java)
mockedFile.read()
verify(mockedFile).read()
MockK:
// MockK
val mockedFile = mockk<File>()
mockedFile.read()
verify { mockedFile.read() }
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论