-
Notifications
You must be signed in to change notification settings - Fork 75
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
base: master
Are you sure you want to change the base?
Conversation
...form.releng/bundles/org.eclipse.test/src/org/eclipse/test/services/LoggingTestExtension.java
Show resolved
Hide resolved
@Bananeweizen is this snippet basically what we discussed? Or am i missing something? |
logs start, stop, duration, error for all tests executed
@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); |
There was a problem hiding this comment.
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.
@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: |
@@ -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, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
No description provided.