10 Replies Latest reply on Jan 2, 2014 3:32 AM by kpiwko

    Run spock and arquillian in-container tests in same project

    luc4

      Hi together,

       

      i played a bit with the spock testrunner and i noticed that it's not possible to execute spock/arquillian in-container tests after adding arquillian-spock-container as dependency to my project.

      Thats because the project now contains two different testrunners in my case junit-container & spock-container.

       

      The tests are failing with:

       

      java.lang.IllegalStateException: Multiple TestRunners found, only one allowed. Check your classpath

                at org.jboss.arquillian.container.test.spi.util.TestRunners.getTestRunner(TestRunners.java:58)

                at org.jboss.arquillian.container.test.spi.util.TestRunners.getTestRunner(TestRunners.java:44)

                at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.executeTest(ServletTestRunner.java:159)

                at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.execute(ServletTestRunner.java:126)

                at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.doGet(ServletTestRunner.java:90)

                at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)

                at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)

                at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)

                at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)

                at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)

                at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)

                at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)

                at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)

                at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)

                at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)

                at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)

                at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)

                at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)

                at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)

                at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)

                at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)

                at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)

                at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)

                at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)

                at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)

                at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)

                at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)

                at com.sun.grizzly.ContextTask.run(ContextTask.java:71)

                at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)

                at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)

                at java.lang.Thread.run(Thread.java:722)

       

       

      Is there a way to overcome this or tell arquillian in some way to use/select the correct runner depending on the test?

       

      Regards

      Luca

       

      Message was edited by: Luca Graf

        • 1. Re: Run spock and arquillian in-container tests in same project
          bmajsak

          At this moment we are following a principle for single SPI extension for TestRunner on classpath. This is the same for container adapters I believe. Is there any concrete reason for you to have both?

           

          Cheers.

          Bartosz

          1 of 1 people found this helpful
          • 2. Re: Run spock and arquillian in-container tests in same project
            luc4

            The reason to have both is that at this time we are just evaluating spock/groovy for writing tests. So i would prefer to start small, write new test with spock and leave existing tests untouched.

            • 3. Re: Run spock and arquillian in-container tests in same project
              bmajsak

              Fair point. But I think for the moment having two under the same hood is impossible. How about creating dedicated module for spock integration tests instead? Would it be challenging with your setup?

              • 4. Re: Run spock and arquillian in-container tests in same project
                luc4

                I hoped i can a avoid the overhead for a seperate module.

                But i see the point that it's normally a uncommon scenario to have more than one testrunner/container adapater in a project.

                 

                Bartosz, many thanks for your help and the clarification!

                • 5. Re: Run spock and arquillian in-container tests in same project
                  bmajsak

                  Well, container adapters you can always switch using things like maven profiles (with specfic resource filtering per profile).  This is how I test my Arquillian extensions.

                   

                  This approach could actually work for your case as well - adding spock sources only for the given profile together with the runner, but this might be as much of an overhead as the dedicated module.

                   

                  And I was a bit lying with container adapters, as it apparently works for managed and remote: https://docs.jboss.org/author/display/ARQ/Multiple+Containers

                  • 6. Re: Run spock and arquillian in-container tests in same project
                    luc4

                    I also thought about using profiles for seperating the testrunner dependencies and test classes. I can imagine that it works well for executing the test with maven, but i think it will get more cumbersome when the tests should be executed in an IDE (switching profiles etc.).

                    • 7. Re: Run spock and arquillian in-container tests in same project
                      bmajsak

                      Well, based on my experience it's not that painful, even with Eclipse If you have m2e-wtp (or jboss tools) you do it with one shortcut.

                      • 8. Re: Run spock and arquillian in-container tests in same project
                        kpiwko

                        It also works if you split execution into phases, e.g. junit runs at test while spock in verify Maven phase. In theory, it might work even for two executions.

                         

                        If I understart testrunners correctly, they are loaded lazily, so you you keep executions separated, it won't matter they are on classpath at the same time.

                        • 9. Re: Run spock and arquillian in-container tests in same project
                          kubam

                          For the record (in case google bring anybody here). This worked for me (both arquillian-[junit|spock]-conteiner were in standard dependencies section):

                           

                          <plugin>

                              <groupId>org.apache.maven.plugins</groupId>

                              <artifactId>maven-surefire-plugin</artifactId>

                              <version>2.16</version>

                              <executions>

                                  <execution>

                                  <id>default-test</id>

                                  <phase>test</phase>

                                  <goals>

                                      <goal>test</goal>

                                  </goals>

                                  <configuration>

                                      <classpathDependencyExcludes>

                                          <classpathDependencyExcludes>org.jboss.arquillian.spock:arquillian-spock-container</classpathDependencyExcludes>

                                      </classpathDependencyExcludes>

                                  </configuration>

                                  </execution>

                                  <execution>

                                  <id>spock-test</id>

                                  <phase>test</phase>

                                  <goals>

                                      <goal>test</goal>

                                  </goals>

                                  <configuration>

                                      <includes>

                                          <include>**/*Specification.java</include>

                                      </includes>

                                      <classpathDependencyExcludes>

                                          <classpathDependencyExcludes>org.jboss.arquillian.junit:arquillian-junit-container</classpathDependencyExcludes>

                                      </classpathDependencyExcludes>

                                  </configuration>

                                  </execution>

                              </executions>

                          </plugin>

                          1 of 1 people found this helpful
                          • 10. Re: Run spock and arquillian in-container tests in same project
                            kpiwko

                            Thanks Kuba,

                             

                            this looks good!