Version 3

    When I run my Arquillian test, I get a ClassNotFoundException for the unit test class its self! How is that possible?

     

    Arquillian automatically adds the test class to the ShrinkWrap archive, so it must be present. Examination of the archive contents using Archive.toString(...) confirms that the test class is being included. So what's going on?

     

    Most likely you're explicitly specifying the test archive name and you've made a simple typo. Archive file names have specific meanings in Java EE - a ".war" is different to a ".jar" is different to a ".ear" is different to a ".rar" and so on. Critically, the location of the class files within each archive type is different.

     

    If you create a ShrinkWrap WarArchive named "test.jar", you'll get a ClassNotFoundException for the test class. The same thing will happen if you create a ShrinkWrap JavaArchive named "test.war". This is an easy mistake to make when converting a unit test from one archive type to another, and one that Arquillian can't detect and warn you about yet. Here's an example of such an error:

     

    @Deployment
    public WebArchive createDeploymen() {
        return ShrinkWrap.create(WebArchive.class, "demo.jar");
    }
    

     

    When run as an Arquillian test, this will result in:

    java.lang.ClassNotFoundException: com.example.shrinkwrapwarbug.DemoTest from [Module "deployment.demo.jar:main" from Service Module Loader]

        ....

     

    though of course your package, archive and class name will be different.

     

    The easiest way to avoid this problem is no to specify the archive name at all. If you leave it out, Arquillian will pick a suitable one for you.