-
Notifications
You must be signed in to change notification settings - Fork 65
Open
Description
Expected Behavior
Injected beans in a test class using @MicronautTest and @MockBean should inject a mock of the bean.
Actual Behaviour
The injected bean is not a mock, but instead the actual instance of the bean.
Steps To Reproduce
- Create a new Micronaut Application (v 4.9.3)
mn create-app --build=gradle_kotlin --jdk=21 --lang=kotlin --test=junit --features=http-client,mockito com.example.kotlin-junit
- Add a simple singleton class
@Singleton
open class EchoServiceImpl {
open fun echo(message: String): String {
return message
}
}- Update the
KotlinJunitTestto create a mock using@MockBean, and inject it into the test class
@MicronautTest
open class KotlinJunitTest {
@Inject
lateinit var application: EmbeddedApplication<*>
@Inject
lateinit var echoService: EchoServiceImpl
@Test
fun testItWorks() {
Assertions.assertTrue(application.isRunning)
}
@Test
fun echoServiceIsMocked() {
Assertions.assertTrue(Mockito.mockingDetails(echoService).isMock)
}
@MockBean(EchoServiceImpl::class)
open fun echoService(): EchoServiceImpl {
return Mockito.mock(EchoServiceImpl::class.java)
}
}Environment Information
No response
Example Application
https://github.com/yacinelakel/micronaut-kotlin-junit-mockbean-issue
Version
4.9.3
Metadata
Metadata
Assignees
Labels
No labels