4 Replies Latest reply on Jan 17, 2018 11:43 AM by Matous Jobanek

    Arquillian with JUnit5 (proof of concept)

    Ondrej Mihályi Newbie

      Hi all,


      I was interested if there is something going on about adding support for JUnit 5 in Arquillian.


      Since there is no work done in this regard, I stated something on my own. I was able to create a Junit 5 extension, which runs a simple test in an Arquillian container.


      Here is my POC on github: GitHub - OndrejM/arquillian-junit5-hacks: POC for arquillian and junit5


      It contains the Junit5 extension and a simple test to demonstrate it's working. If you want to run the tests, use maven profile arquillian-payara-embedded to run them in embedded payara (all is executed in the same JVM, but the tests in the container are executed in a different http request thread - it's easy to debug in one go).


      I still have a big issue to overcome: JUnit 5 still runs the tests also outside arquillian, so the test code (including before/after hooks) is executed twice - as a plain Junit 5 test and also in Arquillian (from a beforeEach JUnit5 hook). It's similar to how TestNG arquillian tests run, with the exception that also the test method is executed on the client side (see more info about Arquillian and TestNG here: Arquillian / TestNG method invocation sequence


      I'm now thinking about creating a copletely new JUnit 5 engine, based on the new Jupiter engine, but tweaking it to avoid running test methods and only forward them to Arquillian. But it's more work and not natural and I'd like to avoid it if possible. I'll consult JUnit 5 team for help too.


      Any ideas are welcome.

        • 1. Re: Arquillian with JUnit5 (proof of concept)
          Bartosz Majsak Master

          Thanks Ondrej for working on it! I'm really happy to see that happening. I will have a look this afternoon and come back with feedback.


          It might be the case that we have to look at implementing the engine itself... I'm a bit concerned that w/o it we could end up with a bit of a hack like we have e.g. in Spock.




          • 2. Re: Arquillian with JUnit5 (proof of concept)
            Ondrej Mihályi Newbie

            I've asked here java - How to implement a custom runner in JUnit5 - Stack Overflow and it seems that we'll need to build an engine after all. I expected that and already started looking into the Jupiter engine source code. I'll need to find some time for it though...

            • 3. Re: Arquillian with JUnit5 (proof of concept)
              David Matejcek Newbie

              I tried it too and updated Ondrej's example because the JUnit API has changed ... but I'm still ending in the following NPE any time I uncoment the body of the beforeEach or afterEach methods.



                      at org.jboss.arquillian.container.test.impl.client.ContainerEventController.lookup(ContainerEventController.java:147)

                      at org.jboss.arquillian.container.test.impl.client.ContainerEventController.createContext(ContainerEventController.java:130)

                      at org.jboss.arquillian.container.test.impl.client.ContainerEventController.createBeforeContext(ContainerEventController.java:114)

                      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)


              If I coment out bodies of both method, test will run only once and fails because the session is null.


              I have added the TestInstancePostProcessor interface (with the empty impl. method because I don't know how to manage the injections - javadoc says it belong here) and removed the runTestInContainer method because I think it is not needed - we need only to "connect some wires" between new JUnit and the container.


              Tested with JUnit 5.0.0, JUnit Platform Launcher 1.0.0, Arquillian 1.2.0-SNAPSHOT, Payara Embedded All and arquillian-glassfish-embedded-3.1 1.0.1 ... and not pushed because it still does not work ...

              • 4. Re: Arquillian with JUnit5 (proof of concept)
                Matous Jobanek Novice

                For more information about the Arquillian JUnit 5 work, please go to this GitHub issue: github.com/arquillian/arquillian-core/issues/137


                As JUnit5 doesn't provide enough SPI points to hook in, then (for now) it's not possible to implement Arquillian JUnit 5 engine or extension.