5 Replies Latest reply on Apr 12, 2016 5:03 AM by mjobanek

    JUnit Rules execution

    erhard

      Hi,

       

      When I tried a newer version of Arquillian, I ran into a problem with JUnit rules.

      Until Arquillian 1.1.5.Final JUnit Rules were executed on client side and on server side. See http://arquillian.org/blog/2014/06/25/arquillian-core-1-1-5-Final/

      Since I set-up and check most things on client-side (database, files), but some on server-side (properties), this was quite convenient. I just checked wether I'm on client or on server and executed the tasks accordingly.

      But with 1.1.5.Final this changed and Rules are executed only on server-side. This makes it much harder to set-up the environment for the test.

      Is there a way to execute set-up and checks for a test on client-side?

        • 1. Re: JUnit Rules execution
          mjobanek

          Hi,

          which version of arquillian-core you are using exactly? Is it the latest one - 1.1.11.final?

          Matous

          • 2. Re: JUnit Rules execution
            erhard

            Yes, i tried 1.1.11.Final. Originally I was using 1.1.0.Final. What I have seen, the change was introduced with 1.1.5.Final. Before that rules were executed on client- and server-side.

            • 3. Re: JUnit Rules execution
              mjobanek

              Well, what I see is that the rule is executed on both the client and server side (for the test method that should be run in container). Do you observe different behaviour?

              • 4. Re: JUnit Rules execution
                erhard

                When I try git@github.com:Gepardec/jboss-examples.git branch b_arquillian_demo_4:

                mvn test -Parquillian-wildfly-managed -Dtest=RuleTest

                ...

                T E S T S

                -------------------------------------------------------

                Running com.gepardec.examples.arquillian.RuleTest

                Apr 07, 2016 10:04:25 PM org.xnio.Xnio <clinit>

                INFO: XNIO version 3.2.2.Final

                Apr 07, 2016 10:04:25 PM org.xnio.nio.NioXnio <clinit>

                INFO: XNIO NIO Implementation Version 3.2.2.Final

                Apr 07, 2016 10:04:25 PM org.jboss.remoting3.EndpointImpl <clinit>

                INFO: JBoss Remoting version 4.0.3.Final

                -- starting: should_create_greeting(com.gepardec.examples.arquillian.RuleTest)

                -- succeeded: should_create_greeting(com.gepardec.examples.arquillian.RuleTest)

                Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 6.172 sec

                 

                The rule is executed on the client (and on the server). (-- starting:...)

                When I change the Arquillian-Version to 1.1.11.Final:

                 

                T E S T S

                -------------------------------------------------------

                Running com.gepardec.examples.arquillian.RuleTest

                Apr 07, 2016 10:06:03 PM org.xnio.Xnio <clinit>

                INFO: XNIO version 3.2.2.Final

                Apr 07, 2016 10:06:03 PM org.xnio.nio.NioXnio <clinit>

                INFO: XNIO NIO Implementation Version 3.2.2.Final

                Apr 07, 2016 10:06:04 PM org.jboss.remoting3.EndpointImpl <clinit>

                INFO: JBoss Remoting version 4.0.3.Final

                Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 4.346 sec

                 

                The rule is executed only on the server.

                This is consistent with the release-notes in Arquillian Core 1.1.5.Final Released · Arquillian Blog:

                This has in the past caused them to be executed both on the Client side and In Container. With 1.1.5.Final, we’ve moved how all this is executed and included @Rules into the Before/After handling.

                This means, @Rules will follow the same rules as @Before/@After, that again follow the execution of @Test. If the @Test is executed In Container, so will the @Rule. If @Test executes on Client, so will the @Rule.

                • 5. Re: JUnit Rules execution
                  mjobanek

                  Hi,

                   

                  thanks for the reproducer.

                  Now, I can see where is my misunderstanding. I understood running a Rule as an invocation of the method Rule.apply(Statement base,...). This method is invoked on both sides. You can check it if you override it in your class SimpleTestHandler and print some output - this output will be visible on both sides.

                  However, the method Statement.evaluate() is invoked only on the side where the test is run - as you said.