-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
MockitoExtension cannot be used with JUnit 5 in OSGi integration tests #1997
Comments
Fragments can be a bit of a pain. @rotty3000 could offer some advice here - he did the OSGi metadata port for the JUnit 5 project itself. They had a similar problem, in that some of the bundles relied on internal packages of other bundles. I think that they ended up exporting the "internal" packages, but flagged them with an attribute to mark them as "internal use only". |
I would also like to see a solution to this issue. Making the mockito-junit-jupiter jar into a fragment which exports the |
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? |
…Extension cannot be used with JUnit 5 in OSGi integration tests without a) giving up the internal nature of some packages b) resorting to substandard solutions like OSGi fragements Signed-off-by: Raymond Augé <raymond.auge@liferay.com>
Looks good to me, I had a look at the build and I know too little about OSGi to understand the effect the API guardian dependencies have but since the classes only carry annotations and the dependency is not required, I do not see any chance of a regression. @TimvdLippe - could you have a second look, you know the build better then me. To me it looks like a good merge. |
For your edification: |
…Extension cannot be used with JUnit 5 in OSGi integration tests without a) giving up the internal nature of some packages b) resorting to substandard solutions like OSGi fragements Signed-off-by: Raymond Augé <raymond.auge@liferay.com>
Today I tried a recent version of Mockito 5 with OSGi but it doesn't work anymore, see also #2708. 😞 |
@wborn Unfortunately I don't have a lot of experience with OSGi, but would be happy to review a PR that fixes it (with an included regression test). Apologies for the breakage! |
I think there needs to be some form of import of the boot loader package that we add. Not sure if such an import is considered in OSGi, but I'd need a reproduction to look into it. |
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
@Mock
s so it would be easier if these mocks can be initialized by annotating classes with@MockitoExtension
instead of usingMockitoAnnotations.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.The text was updated successfully, but these errors were encountered: