Hi Tibor,

I've reworked the commit to keep the JUnit version at 1.3 and use
reflection to get the session. Also, I've fixed the issue with the session
used for scanning tests in main thread that remained open. The formatting
is now in line with the checkstyle rules and all tests pass.
https://github.com/topicusonderwijs/maven-surefire/commit/f30888922b8030ea039980aff413ed5282dca819

Best regards,
Emond

On Sat, Sep 11, 2021 at 12:25 PM Tibor Digana <tibordig...@apache.org>
wrote:

> I do not want to stick to the latest version 1.8.
> We have to stick to version 1.3 as it is right now.
> We do not have a critical issue which could not be solved by reflection.
> This reflection call, I proposed in GH, is made only once, no performance
> penalty.
>
> T
>
> On Sat, Sep 11, 2021 at 7:52 AM Marc Philipp <m...@gradle.com> wrote:
>
> > Hi Emond and Tibor,
> >
> > I’m glad you discovered the new LauncherSession API which was added for
> > this purpose. The JUnit 5.8 GA release will come in the next few days.
> >
> > As you mentrioned, the official documentation does not (yet!) do a good
> > job of explaining its intended use case:
> >
> >
> https://junit.org/junit5/docs/5.8.0-RC1/user-guide/#launcher-api-launcher-session-listeners-custom
> >
> > Here’s a more complete example that I wrote for Gradle’s test
> distribution
> > plugin:
> >
> >
> https://docs.gradle.com/enterprise/test-distribution-gradle-plugin/#junit_5_8_and_later
> >
> > It demonstrates how to initialize a “fixture” only once for an entire
> > session and only if tests are actually going to be executed not just
> > discovered. I’ll make sure to update the official JUnit docs to include a
> > similar example before the release.
> >
> > To only differentiate between the different versions of JUnit in one
> place
> > and stay backwards compatible, you could create an adapter class like
> this:
> >
> > public class BackwardsCompatibleLauncherSession implements AutoCloseable
> {
> >
> >     public static BackwardsCompatibleLauncherSession open() {
> >         try {
> >             LauncherSession launcherSession =
> > LauncherFactory.openSession();
> >             return new
> > BackwardsCompatibleLauncherSession(launcherSession.getLauncher(),
> > launcherSession::close);
> >         } catch (NoSuchMethodError ignore) {
> >             // JUnit Platform version on test classpath does not yet
> > support launcher sessions
> >             return new
> > BackwardsCompatibleLauncherSession(LauncherFactory.create(), () -> {});
> >         }
> >     }
> >
> >     private final Launcher launcher;
> >     private final Runnable onClose;
> >
> >     private BackwardsCompatibleLauncherSession(Launcher launcher,
> Runnable
> > onClose) {
> >         this.launcher = launcher;
> >         this.onClose = onClose;
> >     }
> >
> >     Launcher getLauncher() {
> >         return launcher;
> >     }
> >
> >     @Override
> >     public void close() {
> >         onClose.run();
> >     }
> > }
> >
> > Cheers,
> >
> > Marc
> >
>

Reply via email to