Open ericathedev opened 4 years ago
Hello everybody,
I can confirm the bug. Using an interface instead of a non-interface bean @MockBean
is working.
Regards Simon
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
We have experienced the same. Is there any plan to fix? Thanks
micronaut-projects/micronaut-test#20 was in fact incorrectly closed
Test seems to have passed on the CI?
It didn't run on CI as far as I can tell because I didn't create a PR.
They are running now: https://github.com/micronaut-projects/micronaut-test/pull/264
Hi, we have found this issue as well, using micronaut core 2.2.3 and micronaut test 2.2.1. Is there any update on a fix please? Thanks
what the sample project is missing is:
allOpen {
annotations("io.micronaut.aop.Around", "javax.inject.Singleton")
}
and mocking worked like this:
@get:MockBean(ClassToInject::class)
val mockClassToInject: ClassToInject = mockk()
would this fix your issue?
what the sample project is missing is:
allOpen { annotations("io.micronaut.aop.Around", "javax.inject.Singleton") }
and mocking worked like this:
@get:MockBean(ClassToInject::class) val mockClassToInject: ClassToInject = mockk()
would this fix your issue?
The workaround actually fixed it for me (version 2.3.4)
This should be the default behavior, or at least be mentioned in the documentation
I can confirm the issue. E.g. the "Mocking Collaborators" example for Kotest only works with the MathService
interface and the MathServiceImp
implementation.
Unfortunately the provided workaround didn't work for me in this case.
@sandroboehme
allOpen {
annotations("jakarta.inject.Singleton")
}
worked for me (jakarta.inject instead of javax.inject, Around not required)
This definitely should be documented!
This should also be added to https://micronaut.io/launch
Is there an actual official solution to that? I know I can simply create an interface, but I try to do it for scenarios that are actually needed/justifiable.
Can confirm that it's still an issue in Micronaut 4.4.1
(which I'm using with with Mockk 1.13.10
).
I have spent so many hours trying to get certain tests passing and have only just stumbled upon this, which immediately resolved the problem for me.
I think it would save much time and frustration for many people if this were clearly documented somewhere in the Micronaut docs.
The mocking of non-interface beans not working using the latest
micronautVersion
1.3.2
andmicronaut-test-junit5:1.1.5
. Could this be a reoccurance of https://github.com/micronaut-projects/micronaut-test/issues/20 which was fixed in1.1
?To see the problem in action please look at the example project: https://github.com/ericathedev/test-kt. It uses Micronaut, Kotlin and JUnit5.
Running
ClassWithInjectedFileTest#inject mock classToInject
returnsWhen mocking a class with an interface the test works, see
ClassWithInjectedFileTest#inject mock classToInjectWithInterface
.Thank you in advance!