8 Replies Latest reply on Jun 12, 2012 4:24 AM by gpoul

    ClassNotFoundException for test class in EAR-packaged test: test class not included in test.war?

    robinmacharg

      Hello again,

       

      Following my last post (https://community.jboss.org/thread/200319?tstart=0) I've managed to create a ShrinkWrapped EAR containing the EJBs I want to test (as .jar files). In my test class I have a single CDI @Inject annotation, and a single @Test annotated test (it does an Assert.fail().  I'd LOVE to see a failure, or indeed anything!) I'm saving the archive contents for analysis via a 'deploymentExportPath' arquillian.xml <engine> property.  I'm targeting a managed JBoss AS7.1.1.FINAL install.

       

      The EAR deploys successfully.

       

      I'm seeing a ClassNotFoundException for my ComponentTest class.  Looking at the generated EAR artifact I can see that it has all the dependency JARs included, as well as a test.war file.  application.xml has also been updated appropriately. The test.war only contains /WEB-INF/lib/arquillian-protocol.jar.  I can't see my test class anywhere.  If I run under debug with suspend=y I can see the compiled test class in my target directory.

       

      I've followed the FAQ advice regarding archive naming (https://community.jboss.org/wiki/WhenIRunMyArquillianTestIGetAClassNotFoundExceptionForTheUnitTestClassItsSelfHowIsThatPossible : I leave it up to ShrinkWrap), and I've also followed advice about using <defaultProtocol type="Servlet 3.0"/> in my arquillian.xml along with the appropriate maven dependency (here: https://community.jboss.org/message/622637 and https://issues.jboss.org/browse/AS7-1696).  (BTW Is this still correct advice?)

       

      Is my test class supposed to be packaged inside the test.war and deployed to the server?  Or elsewhere inside the EAR file?  Or do I have to add some config to cause it to be found and included?  It resides in the normal src/test/java location.  I thought Arquillian managed that for me.  Does it remain solely on the client side, or is it passed across to the server somehow?  How does the server-side arquillian stuff know the test class name in the first place (in order that it can't find it)?

       

      What is test.war supposed to contain?  Perhaps someone could provide a directory listing?  I'd love to understand the sequence of events going on under the bonnet during a test.

       

      I'm happy to post specific config if requested, and can hop onto IRC if that would help.

       

      Gratefully,

      Robin

        • 1. Re: ClassNotFoundException for test class in EAR-packaged test: test class not included in test.war?
          gpoul

          Robin Macharg wrote:

           

          Is my test class supposed to be packaged inside the test.war and deployed to the server?  Or elsewhere inside the EAR file?  Or do I have to add some config to cause it to be found and included?  It resides in the normal src/test/java location.  I thought Arquillian managed that for me.  Does it remain solely on the client side, or is it passed across to the server somehow?  How does the server-side arquillian stuff know the test class name in the first place (in order that it can't find it)?

           

          What is test.war supposed to contain?  Perhaps someone could provide a directory listing?  I'd love to understand the sequence of events going on under the bonnet during a test.

           

          The default is to have a test run inside the container. To run inside the container the test class needs to be included in the deployed archive.

          • 2. Re: ClassNotFoundException for test class in EAR-packaged test: test class not included in test.war?
            robinmacharg

            Gerhard Poul wrote:

             

            Robin Macharg wrote:

             

            Is my test class supposed to be packaged inside the test.war and deployed to the server?  Or elsewhere inside the EAR file?  Or do I have to add some config to cause it to be found and included?  It resides in the normal src/test/java location.  I thought Arquillian managed that for me.  Does it remain solely on the client side, or is it passed across to the server somehow?

             

            The default is to have a test run inside the container. To run inside the container the test class needs to be included in the deployed archive.

            Thanks, Gerhard.  That's what I thought.  So my problem is that the test class is not being included.  My understanding is that it should end up in the test.war automatically.  Is this correct?  Any ideas why that would not be happening, or how to make sure it does happen?  Looks like an issue with Arquillian's ear archive handling after I create it with ShrinkWrap in my @deployment.

             

            R

            • 3. Re: ClassNotFoundException for test class in EAR-packaged test: test class not included in test.war?
              robinmacharg

              ...  Looks like an issue with Arquillian's ear archive handling after I create it with ShrinkWrap in my @deployment.

               

              I think I can answer my own question.  I simply added a JAR containing just the test class.  The salient bits of my @Deployment look like this:

               

              @Deployment

              public static EnterpriseArchive createDeployment() {

                  // Example Maven dependency resolution...

                  Collection<JavaArchive> libs = DependencyResolvers.use(MavenDependencyResolver.class)

                      .loadEffectivePom("pom.xml")

                      .artifacts("uk.co.mycompany.project.subproject:SomeLibrary")

                      .resolveAs(JavaArchive.class);

               

                  // MyComponent is also added in as a Module - omitted for brevity

                 

                  // Build the EAR

                  final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class)

                      .setApplicationXML("application.xml")

                      .setManifest("MANIFEST.MF")

                      .addAsLibraries(libs)

                       // The important bit: add the test class manually

                      .addAsLibrary(ShrinkWrap.create(JavaArchive.class)

                                              .addClass(MyComponentTest.class)); // MyComponentTest is this test class

                     

                  // diagnostics

                  System.out.println(ear.toString(true));

               

                  return ear;

              }

               

              This now allows me to get as far as a failing test.  Which, after the last week, counts as progress ;-)

               

              The clue was provided here: https://github.com/aslakknutsen/arquillian-problem/commit/e908165c426e7c49a4f93345ccd0bab4340db989

               

              (related to ARQ-670)  This seems like a gap in the documentation that could be easily filled with a worked EAR-based example, but also an issue with the EAR handling by Arquillian; my expectation all along has been that this should have been done for me.  There may be an JIRA issue for this already, but if not I'm happy to file one.  My Arquillian voodoo is probably not quite up to fixing it, though.

               

              For completeness I should mention that the above works using the <protocolVersion=3.0> tweak mentioned elsewhere.  I've yet to try removing that.

              • 4. Re: ClassNotFoundException for test class in EAR-packaged test: test class not included in test.war?
                gpoul

                I think the problem of the test class not being added when using an EnterpriseArchive is covered by https://issues.jboss.org/browse/ARQ-659

                • 5. Re: ClassNotFoundException for test class in EAR-packaged test: test class not included in test.war?
                  plexusnexus

                  I have exactly the same problem. I also added the test class as library to an EAR but unfortunately the test always succeeds. Even with an always failing assertion.

                   

                  So is it possible at all to test an EAR with serveral modules and libraries with Arquillian at the moment?

                  • 6. Re: ClassNotFoundException for test class in EAR-packaged test: test class not included in test.war?
                    gpoul

                    Oliver, in a remote test the tests are executed by an arquillian servlet inside of a WAR in the deployment EAR. Anything that WAR file can call can be tested. That said, if you're seeing the error mentioned in this thread or on ARQ-659 it's more likely you've not packaged the test where it can be loaded.

                    • 7. Re: ClassNotFoundException for test class in EAR-packaged test: test class not included in test.war?
                      plexusnexus

                      Hi Gehard, thank you. Now it works like a charm. Did I miss something in the reference guide? Does the guide covers this?

                      • 8. Re: ClassNotFoundException for test class in EAR-packaged test: test class not included in test.war?
                        gpoul

                        Other than the ARQ-659, I don't think so. - Just did a quick search and haven't found anything.