1 Reply Latest reply on Nov 24, 2015 10:32 AM by Matous Jobanek

    Arquillian JUnit testing Servlet

    Mike Newnham Newbie



      I'm an Arquillian 'newbie' and I have a question about how to configure a custom Servlet that must be initialized / loaded-on-startup as part of an Arquillian test web archive prior to the test running.


      Firstly - if I omit a web.xml I can get JUnit tests running remotely in JBoss AS properly.  I package a JUnit web-archive using Shrinkwrap that contains Test classes , dependencies and 3rd party libs -- all good. The archive deploys OK and tests run but some will ultimately fail because some of the caches that the system accesses and are loaded by the Init Servlet are not initialized.


      But, if I add a custom web.xml to the archive the Arquillian archive the Test does not initialize properly -- presumably because this file is now preventing the Arquillian framework from being initialized / configured properly...


      As an example, I package the archive below:


        WebArchive war = ShrinkWrap.create( WebArchive.class, "test.war")

        .addPackages(true, "com.mikes")


        // add web.xml

        .setWebXML( new File("src/main/webapp/WEB-INF/web.xml") )


        // dont add empty beans -- adding it doesn't make any difference to the outcome

        // .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")


        // add JBOSS deployment structure -- includes modules on classpath

        .addAsManifestResource(new File("src/main/java/META-INF/jboss-deployment-structure.xml"))



      And I get the following exception -- the Servlet initializes properly on startup but Arquillian is incomplete...



      java.lang.IllegalArgumentException: ArquillianServletRunner not found. Could not determine ContextRoot from ProtocolMetadata, please contact DeployableContainer developer.

        at org.jboss.arquillian.protocol.servlet.ServletUtil.determineBaseURI(ServletUtil.java:69)

        at org.jboss.arquillian.protocol.servlet.ServletURIHandler.locateTestServlet(ServletURIHandler.java:60)

        at org.jboss.arquillian.protocol.servlet.ServletMethodExecutor.invoke(ServletMethodExecutor.java:84)

        at org.jboss.arquillian.container.test.impl.execution.RemoteTestExecuter.execute(RemoteTestExecuter.java:109)

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



      The web.xml is nothing special....


      <web-app xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"

      version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">











      I'm not really sure what else to try -- I am sure there must be a way to have Arquillian 'merge' or 'inject' custom web.xml with its servlet configuration ?


      I am using the following arquillian dependencies:

      • arquillian-bom 1.1.10.Final
      • jboss-as-arquillian-container-remote  7.1.1.Final
      • arquillian-protocol-servlet
      • arquillian-junit-container



      Thanks in advance !




        • 1. Re: Arquillian JUnit testing Servlet
          Matous Jobanek Novice

          Hi Mike,

          I package a JUnit web-archive using Shrinkwrap that contains Test classes , dependencies and 3rd party libs

          I'm not sure what you are trying to do.. Do you want to run tests inside of the container and to do so you package the test classes manually? If yes - you don't have to do it - Arquillian does everything necessary for running tests inside of the container - deploys test classes and manages all the communication with the tests and retrieves the test reports.


          Have you specified the default protocol there in the arquillian.xml file?

          <defaultProtocol type="Servlet 3.0" />