Skip to content
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

How to use junit.jupiter Extensions in OSGi and plain java #2510

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jukzi
Copy link
Contributor

@jukzi jukzi commented Nov 4, 2024

No description provided.

@jukzi
Copy link
Contributor Author

jukzi commented Nov 4, 2024

@Bananeweizen is this snippet basically what we discussed? Or am i missing something?

logs start, stop, duration, error for all tests executed
@Bananeweizen
Copy link
Contributor

@jukzi The mechanics look good to me. I haven't used the properties file yet (because we have all properties in the maven invocation for our company projects), therefore I can't judge that file. Also if you just want the timing as such, https://github.com/junit-team/junit5/blob/main/documentation/src/test/java/example/timing/TimingExtension.java would be available.

You also had mentioned a problem with TestSuites, e.g. forgetting to add new tests to existing suites, or re-running suites taking long time? Can you eventually point me to some existing discussion or bug about that? I run all the tests in our company without using any suites, therefore I can't really remember anymore which problem that was...

long t1 = System.nanoTime();
long t0 = getStore(context).remove("TIME", long.class);
String took = " after: " + (t1 - t0) / 1_000_000 + "ms";
Throwable t = context.getExecutionException().orElse(null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's the most simple way to judge the test outcome. alternatively you could also implement https://junit.org/junit5/docs/5.4.1/api/org/junit/jupiter/api/extension/TestWatcher.html, which gets notified on test results. Not sure what fits better for your case.

@jukzi
Copy link
Contributor Author

jukzi commented Nov 4, 2024

@Bananeweizen the main point is that somehow "junit.jupiter.extensions.autodetection.enabled=true" has to be set (you did not mention that) otherwise it does not work.

regarding TestSuite see:
eclipse-platform/eclipse.platform.ui#2391 and
https://www.eclipse.org/lists/jdt-dev/threads.html#02401

@@ -11,7 +11,9 @@ Require-Bundle: org.apache.ant,
org.eclipse.core.runtime,
org.eclipse.ui.ide.application,
org.eclipse.equinox.app,
org.junit
org.apache.aries.spifly.dynamic.bundle,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should not the bundle org.apache.aries.spifly.dynamic.bundle by it's name.

If you want to make sure that this bundle properly registers it's provided service at the OSGi service loader mediator is present then you should instead register the extension as provided Java service:

Require-Capability: osgi.extender;filter:="(&(osgi.extender=osgi.serviceloader.registrar)
 (version>=1.0.0)(!(version>=2.0.0)))"
Provide-Capability: osgi.serviceloader;osgi.serviceloader=org.junit.jupiter.api.extension.Extension

Maybe this also helps with your registration issue, because without these changes the extension is basically invisible in an OSGi runtime. Of course this requires also that the JUnit bundles are configured correspondingly for OSGi runtimes as service consumer.
For reference see
https://aries.apache.org/documentation/modules/spi-fly.html#specconf
https://docs.osgi.org/specification/osgi.cmpn/8.0.0/service.loader.html

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this also helps with your registration issue

Which issue? this example seems to work fine. I would like to understand what is changed/improved if i would use the "Capability" thing instead. Especially how that would work in an non-osgi environment like SWT tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants