MockitoExtension cannot be used with JUnit 5 in OSGi integration tests
See original GitHub issueThe Mockito junit-jupiter JAR is missing OSGi bundle manifest entries so it cannot be used in OSGi integration tests.
We run some OSGi integration tests (using bnd) that have @Mock
s so it would be easier if these mocks can be initialized by annotating classes with @MockitoExtension
instead of using MockitoAnnotations.openMocks(this)
, see for example this FirmwareUpdateServiceTest.
What may complicate adding the manifest entries is that MockitoExtension
is importing internal classes which aren’t exported by the mockito-core bundle. What may help is to make junit-jupiter a bundle fragment with mockito-core as host.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
JUnit 5 throw method not found with Mockito.extension
I am updating a test from JUnit 4 to JUnit 5 (Jupiter). Among the ordinary annotation adaptations such as @BeforeEach I am using...
Read more >Mockito and JUnit 5 - Using ExtendWith - Baeldung
In this quick tutorial, we'll show how to integrate Mockito with the JUnit 5 extension model. To learn more about the JUnit 5...
Read more >Solved: junit5 and Mockito tests not injecting the Resourc...
The servlet is not resolving the service so I am unable to perform a proper test. I am using the mockito-core 3.3.3 ,...
Read more >JUnit 5: leveraging new features for testing - Netcentric
Thinking of emigrating to JUnit5? Our experts share their insights on how and why you should leveraging the new state-of-the-art features ...
Read more >How to Replace Rules in JUnit 5 - Code Affine
A recurring pattern for rules is to provide a service in tandem with an annotation that is used to mark and/or configure test...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve got a set of changes that makes mockito-junit-jupiter work in OSGi using the same strategy that junit5 used to identify “friend” packages that are exported but not intended for public use outside of mockito.
@raphw do you think your team would be interested?
For your edification: a) apiguardian does not bring with it any runtime dependencies (confirmed by the OSGi metadata) b) the interaction between API guardian and bnd is explained here c) the build adds a
verifyOSGi
gradle task glued ontocheck
to make sure that future changes do not break the relationship required between mockito-core and mockito-junit-jupiter such that they continue working together in OSGi