0 Replies Latest reply on Aug 12, 2011 7:30 AM by avrecko

    Tests load in wrong ClassLoader

    avrecko

      Hi,

       

      arquillian is pretty impressive but there is one major thing that is bothering me:

       

      From the documentation I got the feeling the test itself is run on the server - it sure doesn't feel like that is the case.

       

      Using Alpha5 with Tomcat6 and Jetty7 (embedded) I get this behavior

       

      @Deployment
      public static WebArchive createWar() {
           .... addAsLibraries(someJarThatIncludesFoo); ...
      }
      
      @Test
      public void testOnServer(){
           this.getClass().getClassLoader().loadClass("test.Foo"); // I get ClassNotFoundException
           Thread.currentThread().getContextClassLoader().loadClass("test.Foo"); // works with Jetty but not with Tomcat
      }
      

       

      I'd expect this.getClass().getClassLoader() to return WebAppLoader instead it returns AppClassLoader.

       

      Right now I worked around by using Servlets/Listeners (they get loaded in the correct ClassLoader) and doing stuff like

       

      @Test
      public void testFromClient(){
          String body = readAllAndClose(new URL(baseUrl, "/Test").openStream());
           ....
      }
      

      it would be a lot more convenient if the Test is loaded in the WebAppClassLoader instead of AppClassLoader.

       

      Am I missing something or is this the desired behavior? Surely it is not?

       

      Cheers

      Alen