question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mockito extension not working with `@QuarkusTest`

See original GitHub issue

Describe the bug

Having a test with:

@QuarkusTest
@ExtendWith(MockitoExtension.class)
class Test {

    @Captor
    ArgumentCaptor<Whatever> captor;
}

will not correctly utilize the MockitoExtension and Mockito annotated fields will not be initialized.

Expected behavior

  • org.mockito annotations are correctly initialized

Actual behavior

Seems that Mockito extension is initalizing the fields in the different test instance. Simple debugging I did showed that mockito correctly initialized fields in my test instance {GrpcClientsTest@10823}, while the actual instance being used in the test is {GrpcClientsTest@10895}.

How to Reproduce?

No response

Output of uname -a or ver

Linux ise-Precision-5550 5.13.0-39-generic #44~20.04.1-Ubuntu SMP Thu Mar 24 16:43:35 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

No response

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.8.0.Final

Build tool (ie. output of mvnw --version or gradlew --version)

pache Maven 3.8.4 (9b656c72d54e5bacbed989b64718c159fe39b537) Maven home: /home/ise/.m2/wrapper/dists/apache-maven-3.8.4-bin/52ccbt68d252mdldqsfsn03jlf/apache-maven-3.8.4 Java version: 17.0.2, vendor: Private Build, runtime: /usr/lib/jvm/java-17-openjdk-amd64 Default locale: en_US, platform encoding: UTF-8 OS name: “linux”, version: “5.13.0-39-generic”, arch: “amd64”, family: “unix”

Additional information

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
geoandcommented, Apr 14, 2022

There are various limitations, yes.

I never said it was a good approach, it was however the only one that allowed us to support the feature set we need.

If JUnit supports loading test classes from a custon ClassLoader in the future (there is an open issue), we could ditch this approach.

0reactions
geoandcommented, Apr 14, 2022

It only works for beans

Read more comments on GitHub >

github_iconTop Results From Across the Web

Testing Your Application - Quarkus
These tests will not work if run in the same phase as @QuarkusTest as Quarkus has not yet created the final artifact. The...
Read more >
Missing mockito-junit-jupiter in quarkus-junit5-mockito #11361
I am in favor of leaving it as is, as the quarkus-junit5-mockito extension does not interact with the mockito junit5 extension in any...
Read more >
QuarkusTest-Annotation + Mockito Result in ClassLoader Errors
We are using quarkus version 1.12.1.Final and the extensions are configured by the bom, therefor they should work together. Did I misunderstood ...
Read more >
Home of Quarkus Cheat-Sheet - GitHub Pages
This does not work when using native image testing. A stereotype annotation io.quarkus.test.Mock is provided declaring @Alternative , @Priority(1) ...
Read more >
Testing Quarkus Applications | Baeldung
This test, annotated with @QuarkusTest, first starts the Quarkus ... Also, take notice that, at the moment, injection does not work with ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found