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.

MockitoExtension cannot be used with JUnit 5 in OSGi integration tests

See original GitHub issue

The 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 @Mocks 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:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
rotty3000commented, Sep 17, 2020

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?

0reactions
rotty3000commented, Sep 17, 2020

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 onto check 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

Read more comments on GitHub >

github_iconTop 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 >

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