-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
QuarkusComponentTest -> No ParameterResolver registered for parameter #41224
Comments
@octopus-prime It is not.
Not really, you can use The difference is that
We don't use the If you need to inject an unconfigured mock in a test method argument then replace the |
->
|
Could you share the full stacktrace pls? Also it would be great if you could share a small project that would contain the "full" setup of your test. |
https://github.com/octopus-prime/qct The 'BrokenFooControllerTest' will produce
|
👍 I'll take a look tomorrow. |
@octopus-prime Ok, so the problem is that Now in the reproducer, @Test
void getFoo() {
Foo foo = Mockito.mock(Foo.class);
FooResponse fooResponse = Mockito.mock(FooResponse.class);
when(fooRepository.findFoo("1")).thenReturn(foo);
when(fooMapper.mapFoo(foo)).thenReturn(fooResponse);
FooResponse result = fooController.getFoo("1");
assertEquals(result, fooResponse);
} Again, for I wonder if we should change the behavior but I think that it does not make sense to create a mock bean for such an object. It seems like a misuse of the API. But I agree that we should at least improve the error message so that it's more clear. If we find a way to detect this kind of misuse... CC @manovotn |
Strange... "@InjectMock is not intended for injection of a mock of any arbitrary object."... But
Works fine. However... both solutions need extra-lines of code :-( |
Indeed, there's an inconsistency because
Yes, they need. There's one more alternative: import org.mockito.Mock;
import io.quarkus.test.component.SkipInject;
@ExtendWith(MockitoExtension.class)
@SkipInject // needed to tell the QuarkusComponentTest to skip the @Mock params
@Test
void getFoo(@Mock Foo foo, @Mock FooResponse fooResponse) {
when(fooRepository.findFoo("1")).thenReturn(foo);
when(fooMapper.mapFoo(foo)).thenReturn(fooResponse);
FooResponse result = fooController.getFoo("1");
assertEquals(result, fooResponse);
} |
I think a sensible approach is to:
The way JUnit works, you should be able to meld together several extensions and Mockito has their own one that you can leverage for what you are trying to do. What @mkouba suggests in the last comment is IMO the "cleanest" approach you can get. |
We will also skip param injection for params annotated with |
- take into consideration method params with `@InjectMock` when marking beans as unremovable - document that `@InjectMock` is not intended as a universal replacement for the functionality provided by the Mockito JUnit extension. - also skip param injection for params annotated with `@org.mockito.Mock` so that `@SkipInject` is not needed. - fixes quarkusio#41224
@octopus-prime pull request sent! ;-) |
- take into consideration method params with `@InjectMock` when marking beans as unremovable - document that `@InjectMock` is not intended as a universal replacement for the functionality provided by the Mockito JUnit extension. - also skip param injection for params annotated with `@org.mockito.Mock` so that `@SkipInject` is not needed. - fixes quarkusio#41224 (cherry picked from commit 86bba7a)
- take into consideration method params with `@InjectMock` when marking beans as unremovable - document that `@InjectMock` is not intended as a universal replacement for the functionality provided by the Mockito JUnit extension. - also skip param injection for params annotated with `@org.mockito.Mock` so that `@SkipInject` is not needed. - fixes quarkusio#41224
- take into consideration method params with `@InjectMock` when marking beans as unremovable - document that `@InjectMock` is not intended as a universal replacement for the functionality provided by the Mockito JUnit extension. - also skip param injection for params annotated with `@org.mockito.Mock` so that `@SkipInject` is not needed. - fixes quarkusio#41224
Describe the bug
As far as i understand QuarkusComponentTest is just 'mockito-test' with other annotations.
So QuarkusComponentTest still relies on Mockito.
So let's convert a 'mockito-test' into a QuarkusComponentTest
->
Expected behavior
A fully initialized mockito - with parameter resolvers.
Actual behavior
org.junit.jupiter.api.extension.ParameterResolutionException: No ParameterResolver registered for parameter
How to Reproduce?
Run the QuarkusComponentTest
Output of
uname -a
orver
No response
Output of
java -version
No response
Quarkus version or git rev
No response
Build tool (ie. output of
mvnw --version
orgradlew --version
)No response
Additional information
Same failure with
void readFall(@InjectMock Fall fall, @InjectMock FallResponse fallResponse) {
The text was updated successfully, but these errors were encountered: