0 Replies Latest reply on Apr 15, 2009 9:52 PM by Daniel Kluge

    TestNG: Difference between test classpath & surefire test classpath

    Daniel Kluge Newbie

      Hi all,


      I have a question about the execution of a TestNG test in the Embedded JBoss with Maven:
      If I am executing an TestNG test with Maven(Surefire plugin) which classpath is important:
      The surefire test classpath or the test classpath?


      I want to illustrate the problem. Here is my pom.xml:



      <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
      
        <parent>
          <groupId>com.mypackage</groupId>
          <artifactId>myproject-all</artifactId>
          <version>${myproject.version}</version>
        </parent>
      
        <modelVersion>4.0.0</modelVersion>
        <groupId>com.mypackage</groupId>
        <artifactId>myproject-ejb</artifactId>
        <packaging>ejb</packaging>
        <name>MYPROJECT EJB</name>
      
        <build>
          <!-- resources>
            <resource>
              <directory>${myproject.home}/${myproject.release}/src/main/resources</directory>
              <includes>
                <include>**/*</include>
              </includes>
              <filtering>true</filtering>
            </resource>
          </resources-->
      
          <plugins>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-ejb-plugin</artifactId>
              <configuration>
                <ejbVersion>3.0</ejbVersion>
                <generateClient>true</generateClient>
                <archive>
                  <manifest>
                    <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
                    <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                    <addClasspath>true</addClasspath>
                    <classpathPrefix>lib/</classpathPrefix>
                  </manifest>
                  <manifestEntries>
                    <Class-Path>lib/myproject-server.jar</Class-Path>
                  </manifestEntries>            
                </archive>
              </configuration>
            </plugin>
      
           <!-- Surefire  -->
           <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.4.3</version>
                <configuration>
                               <useManifestOnlyJar>false</useManifestOnlyJar>
                          <additionalClasspathElements>
                              <additionalClasspathElement>${myproject.home}/myproject-ejb/bootstrap</additionalClasspathElement>
                          </additionalClasspathElements>
                          <forkMode>once</forkMode>
                          <jvm>${myproject.java}</jvm>
                          <argLine>-Dsun.lang.ClassLoader.allowArraySyntax=true</argLine>
              </configuration>
           </plugin>
          <!-- ==================== -->
          </plugins>
      
        </build>
        <dependencyManagement>
              <dependencies>
                  <dependency>
                      <groupId>javax.transaction</groupId>
                      <artifactId>jta</artifactId>
                      <version>1.0.1B</version>
                      <scope>provided</scope>
                  </dependency>
              </dependencies>
        </dependencyManagement>
        
            <dependencies>
              <!-- Embedded JBoss dependencies
                   These make me a tad nervous because there are duplicate libraries on the test classpath.
                   However, Maven gives you no way to tare the classpath to zero and start fresh. -->
              <dependency>
                     <groupId>org.jboss.seam.embedded</groupId>
                     <artifactId>jboss-embedded-all</artifactId>
                     <version>beta3.SP4</version>
                     <scope>test</scope>
                </dependency>
              <dependency>
                  <groupId>org.jboss.seam.embedded</groupId>
                  <artifactId>hibernate-all</artifactId>
                  <version>beta3.SP4</version>
                     <scope>test</scope>
              </dependency>
              <dependency> 
                     <groupId>org.jboss.seam.embedded</groupId>
                     <artifactId>thirdparty-all</artifactId> 
                     <version>beta3.SP4</version>
                     <scope>test</scope>
                </dependency>
              <!-- /Embedded JBoss dependencies -->
              <dependency>
                     <groupId>javax.servlet</groupId>
                     <artifactId>servlet-api</artifactId>
                     <version>2.5</version>
                     <scope>provided</scope>
                </dependency>
                <dependency>
                     <groupId>javax.ejb</groupId>
                     <artifactId>ejb-api</artifactId>
                  <version>3.0</version>
                     <scope>provided</scope>
                </dependency>
              <dependency>
                  <groupId>javax.el</groupId>
                  <artifactId>el-api</artifactId>
                  <version>1.0</version>
                  <scope>provided</scope>
              </dependency>
              <dependency>
                  <groupId>org.jboss.el</groupId>
                  <artifactId>jboss-el</artifactId>
                  <version>2.0.1.GA</version>
                  <scope>provided</scope>
              </dependency>
              <dependency>
                  <groupId>com.sun.facelets</groupId>
                  <artifactId>jsf-facelets</artifactId>
                  <version>1.1.14</version>
                  <scope>runtime</scope>
              </dependency>
              <dependency>
                  <groupId>javax.faces</groupId>
                  <artifactId>jsf-api</artifactId>
                  <version>1.2_09-BETA1</version>
                  <scope>provided</scope>
              </dependency>
              <dependency>
                  <groupId>javax.faces</groupId>
                  <artifactId>jsf-impl</artifactId>
                  <version>1.2_12</version>
                  <scope>provided</scope>
              </dependency>
              <dependency>
                  <groupId>javax.persistence</groupId>
                  <artifactId>persistence-api</artifactId>
                  <version>1.0</version>
                  <scope>provided</scope>
              </dependency>
              <dependency>
                  <groupId>org.hibernate</groupId>
                  <artifactId>hibernate-validator</artifactId>
                  <version>3.0.0.GA</version>
                  <scope>compile</scope>
              </dependency>
              <dependency>
                     <groupId>org.jboss.seam</groupId>
                     <artifactId>jboss-seam</artifactId>
                     <version>2.1.1.GA</version>
                     <scope>provided</scope>
                </dependency>
              <dependency>
                  <groupId>org.jboss.seam</groupId>
                  <artifactId>jboss-seam-debug</artifactId>
                  <version>2.1.1.GA</version>
                  <scope>runtime</scope>
              </dependency>
              <dependency>
                  <groupId>org.testng</groupId>
                  <artifactId>testng</artifactId>
                  <version>5.6</version>
                  <scope>test</scope>
              </dependency>
          </dependencies>
      </project>



      If I am executing the test with Maven now, I get this error:


      CONTEXTS MISSING DEPENDENCIES: Name -> Dependency{Required State:Actual State}
      
      jboss.j2ee:jar=classes,name=BeanA,service=EJB3
       -> <UNKNOWN>{Described: UNRESOLVED Demands 'persistence.units:jar=classes.jar,unitName=MYPROJ }
      
      jboss.j2ee:jar=classes,name=BeanB,service=EJB3
       -> <UNKNOWN>{Described: UNRESOLVED Demands 'persistence.units:jar=classes.jar,unitName=MYPROJ }
      
      jboss.j2ee:jar=classes,name=BeanC,service=EJB3
       -> <UNKNOWN>{Described: UNRESOLVED Demands 'persistence.units:jar=classes.jar,unitName=MYPROJ }
      
      persistence.units:jar=classes.jar,unitName=MYPROJ
       -> <UNKNOWN>{Described: UNRESOLVED Demands 'jboss.jca:name=jdbc/MYPROJ,service=DataSourceBinding }
      
      
       CONTEXTS IN ERROR: Name -> Error
      
      <UNKNOWN> ->  UNRESOLVED Demands 'jboss.jca:name=jdbc/myproj,service=DataSourceBinding 
      
      ]]>
                  </message>
                  <full-stacktrace>
                    <![CDATA[org.jboss.deployers.client.spi.IncompleteDeploymentException: Summary of incomplete deployments (SEE PREVIOUS ERRORS FOR DETAILS):
      
       CONTEXTS MISSING DEPENDENCIES: Name -&gt; Dependency{Required State:Actual State}
      
      jboss.j2ee:jar=classes,name=BeanA,service=EJB3
       -&gt; &lt;UNKNOWN&gt;{Described: UNRESOLVED Demands 'persistence.units:jar=classes.jar,unitName=MYPROJ }
      
      jboss.j2ee:jar=classes,name=BeanB,service=EJB3
       -&gt; &lt;UNKNOWN&gt;{Described: UNRESOLVED Demands 'persistence.units:jar=classes.jar,unitName=MYPROJ }
      
      persistence.units:jar=classes.jar,unitName=MYPROJ
       -&gt; &lt;UNKNOWN&gt;{Described: UNRESOLVED Demands 'jboss.jca:name=jdbc/myproj,service=DataSourceBinding }
      
      
       CONTEXTS IN ERROR: Name -&gt; Error
      
      &lt;UNKNOWN&gt; -&gt;  UNRESOLVED Demands 'jboss.jca:name=jdbc/myproj,service=DataSourceBinding



      Now the the extract of the test classpath:



      [DEBUG]   (f) reportsDirectory = C:\Projects\My_project\main\Sourcen_maven\myproject-ejb\target\surefire-reports
      [DEBUG]   (f) session = org.apache.maven.execution.MavenSession@157c2bd
      [DEBUG]   (f) testClassesDirectory = C:\Projects\My_project\main\Sourcen_maven\myproject-ejb\target\test-classes
      [DEBUG]   (f) testNGArtifactName = org.testng:testng
      [DEBUG]   (f) testSourceDirectory = C:\Projects\My_project\main\Sourcen_maven\myproject-ejb\src\test\java
      [DEBUG]   (f) trimStackTrace = true
      [DEBUG]   (f) useFile = true
      [DEBUG]   (f) useManifestOnlyJar = false
      [DEBUG]   (f) workingDirectory = C:\Projects\My_project\main\Sourcen_maven\myproject-ejb
      [DEBUG] -- end configuration --
      [INFO] [surefire:test]
      [DEBUG] Setting context classloader for plugin to: /plugins/org.apache.maven.plugins:maven-surefire-plugin:2.4.3@48/thread:main (instance is: ClassRealm[/plugins/org.apache.maven.plugins:maven-surefire-plugin:2.4.3@48/thread:main, parent: ClassRealm[plexus.core, parent: null]])
      [DEBUG] dummy:dummy:jar:1.0 (selected for null)
      [DEBUG]   org.apache.maven.surefire:surefire-booter:jar:2.4.3:runtime (selected for runtime)
      [DEBUG]     org.apache.maven.surefire:surefire-api:jar:2.4.3:runtime (selected for runtime)
      [DEBUG] Adding to surefire booter test classpath: c:\Projects\javalibs\MavenRepository\org\apache\maven\surefire\surefire-booter\2.4.3\surefire-booter-2.4.3.jar
      [DEBUG] Adding to surefire booter test classpath: c:\Projects\javalibs\MavenRepository\org\apache\maven\surefire\surefire-api\2.4.3\surefire-api-2.4.3.jar
      [DEBUG] dummy:dummy:jar:1.0 (selected for null)
      [DEBUG]   org.testng:testng:jar:5.6:test (selected for test)
      [DEBUG]     junit:junit:jar:3.8.1:test (selected for test)
      [DEBUG] Adding to surefire booter test classpath: c:\Projects\javalibs\MavenRepository\org\testng\testng\5.6\testng-5.6.jar
      [DEBUG] Adding to surefire booter test classpath: c:\Projects\javalibs\MavenRepository\junit\junit\3.8.1\junit-3.8.1.jar
      [DEBUG] dummy:dummy:jar:1.0 (selected for null)
      [DEBUG] Adding managed dependencies for unknown:surefire-testng
      [DEBUG]   org.apache.maven.surefire:surefire-api:jar:2.4.3
      [DEBUG]   org.apache.maven.surefire:surefire-booter:jar:2.4.3
      [DEBUG]   org.codehaus.plexus:plexus-utils:jar:1.5.1
      [DEBUG]   org.apache.maven.surefire:surefire-testng:jar:2.4.3:test (selected for test)
      [DEBUG]     junit:junit:jar:3.8.1:test (selected for test)
      [DEBUG]     org.apache.maven.surefire:surefire-api:jar:2.4.3:test (selected for test)
      [DEBUG]     org.apache.maven:maven-artifact:jar:2.0:test (selected for test)
      [DEBUG]       org.codehaus.plexus:plexus-utils:jar:1.0.4:test (selected for test)
      [DEBUG]     org.testng:testng:jar:jdk15:5.7:test (selected for test)
      [DEBUG] Adding to surefire test classpath: c:\Projects\javalibs\MavenRepository\org\apache\maven\surefire\surefire-testng\2.4.3\surefire-testng-2.4.3.jar
      [DEBUG] Adding to surefire test classpath: c:\Projects\javalibs\MavenRepository\junit\junit\3.8.1\junit-3.8.1.jar
      [DEBUG] Adding to surefire test classpath: c:\Projects\javalibs\MavenRepository\org\apache\maven\surefire\surefire-api\2.4.3\surefire-api-2.4.3.jar
      [DEBUG] Adding to surefire test classpath: c:\Projects\javalibs\MavenRepository\org\apache\maven\maven-artifact\2.0\maven-artifact-2.0.jar
      [DEBUG] Adding to surefire test classpath: c:\Projects\javalibs\MavenRepository\org\codehaus\plexus\plexus-utils\1.0.4\plexus-utils-1.0.4.jar
      [DEBUG] Test Classpath :
      [DEBUG]   C:\Projects\My_project\main\Sourcen_maven\myproject-ejb\target\test-classes
      [DEBUG]   C:\Projects\My_project\main\Sourcen_maven\myproject-ejb\target\classes
      [DEBUG]   c:\Projects\javalibs\MavenRepository\junit\junit\4.0\junit-4.0.jar
      [DEBUG]   c:\Projects\javalibs\MavenRepository\log4j\log4j\1.2.14\log4j-1.2.14.jar
      [DEBUG]   c:\Projects\javalibs\MavenRepository\org\jboss\seam\embedded\jboss-embedded-all\beta3.SP4\jboss-embedded-all-beta3.SP4.jar
      [DEBUG]   c:\Projects\javalibs\MavenRepository\org\jboss\seam\embedded\jboss-embedded-api\beta3.SP4\jboss-embedded-api-beta3.SP4.jar
      [DEBUG]   c:\Projects\javalibs\MavenRepository\org\jboss\microcontainer\jboss-deployers-client-spi\2.0.0.Beta6\jboss-deployers-client-spi-2.0.0.Beta6.jar
      [DEBUG]   c:\Projects\javalibs\MavenRepository\org\jboss\microcontainer\jboss-deployers-core-spi\2.0.0.Beta6\jboss-deployers-core-spi-2.0.0.Beta6.jar
      [DEBUG]   c:\Projects\javalibs\MavenRepository\org\jboss\seam\embedded\hibernate-all\beta3.SP4\hibernate-all-beta3.SP4.jar
      [DEBUG]   c:\Projects\javalibs\MavenRepository\org\jboss\seam\embedded\thirdparty-all\beta3.SP4\thirdparty-all-beta3.SP4.jar
      [DEBUG]   c:\Projects\javalibs\MavenRepository\javax\servlet\servlet-api\2.5\servlet-api-2.5.jar
      [DEBUG]   c:\Projects\javalibs\MavenRepository\javax\ejb\ejb-api\3.0\ejb-api-3.0.jar
      [DEBUG]   c:\Projects\javalibs\MavenRepository\javax\el\el-api\1.0\el-api-1.0.jar
      [DEBUG]   c:\Projects\javalibs\MavenRepository\org\jboss\el\jboss-el\2.0.1.GA\jboss-el-2.0.1.GA.jar
      [DEBUG]   c:\Projects\javalibs\MavenRepository\com\sun\facelets\jsf-facelets\1.1.14\jsf-facelets-1.1.14.jar
      [DEBUG]   c:\Projects\javalibs\MavenRepository\javax\faces\jsf-api\1.2_09-BETA1\jsf-api-1.2_09-BETA1.jar
      [DEBUG]   c:\Projects\javalibs\MavenRepository\javax\faces\jsf-impl\1.2_12\jsf-impl-1.2_12.jar
      [DEBUG]   c:\Projects\javalibs\MavenRepository\javax\persistence\persistence-api\1.0\persistence-api-1.0.jar
      [DEBUG]   c:\Projects\javalibs\MavenRepository\org\hibernate\hibernate-validator\3.0.0.GA\hibernate-validator-3.0.0.GA.jar
      [DEBUG]   c:\Projects\javalibs\MavenRepository\org\hibernate\hibernate\3.2.4.sp1\hibernate-3.2.4.sp1.jar
      [DEBUG]   c:\Projects\javalibs\MavenRepository\net\sf\ehcache\ehcache\1.2.3\ehcache-1.2.3.jar
      [DEBUG]   c:\Projects\javalibs\MavenRepository\commons-logging\commons-logging\1.0.4\commons-logging-1.0.4.jar
      [DEBUG]   c:\Projects\javalibs\MavenRepository\commons-collections\commons-collections\2.1.1\commons-collections-2.1.1.jar
      [DEBUG]   c:\Projects\javalibs\MavenRepository\javax\transaction\jta\1.0.1B\jta-1.0.1B.jar
      [DEBUG]   c:\Projects\javalibs\MavenRepository\asm\asm-attrs\1.5.3\asm-attrs-1.5.3.jar
      [DEBUG]   c:\Projects\javalibs\MavenRepository\dom4j\dom4j\1.6.1\dom4j-1.6.1.jar
      [DEBUG]   c:\Projects\javalibs\MavenRepository\antlr\antlr\2.7.6\antlr-2.7.6.jar
      [DEBUG]   c:\Projects\javalibs\MavenRepository\cglib\cglib\2.1_3\cglib-2.1_3.jar
      [DEBUG]   c:\Projects\javalibs\MavenRepository\asm\asm\1.5.3\asm-1.5.3.jar
      [DEBUG]   c:\Projects\javalibs\MavenRepository\org\jboss\seam\jboss-seam\2.1.1.GA\jboss-seam-2.1.1.GA.jar
      [DEBUG]   c:\Projects\javalibs\MavenRepository\org\jboss\seam\jboss-seam-debug\2.1.1.GA\jboss-seam-debug-2.1.1.GA.jar
      [DEBUG]   c:\Projects\javalibs\MavenRepository\org\jboss\seam\jboss-seam\2.1.1.GA\jboss-seam-2.1.1.GA.jar
      [DEBUG]   c:\Projects\javalibs\MavenRepository\org\testng\testng\5.6\testng-5.6.jar
      [DEBUG]   c:\Projects\javalibs\MavenRepository\org\apache\axis\axis\1.4\axis-1.4.jar
      [DEBUG]   c:\Projects\javalibs\MavenRepository\org\apache\axis\axis-jaxrpc\1.4\axis-jaxrpc-1.4.jar
      [DEBUG]   C:/Projects/My_project/main/Sourcen_maven/myproject-ejb/bootstrap
      [DEBUG] Setting system property [user.dir]=[C:\Projects\My_project\main\Sourcen_maven\myproject-ejb]
      [DEBUG] Setting system property [localRepository]=[c:/Projects/javalibs/MavenRepository]
      [DEBUG] Setting system property [basedir]=[C:\Projects\My_project\main\Sourcen_maven\myproject-ejb]
      [INFO] Surefire report directory: C:\Projects\My_project\main\Sourcen_maven\myproject-ejb\target\surefire-reports
      



      As you see: The embedded jars are included in the test classpath, but not in the surefire test classpath.


      Therefore my question: Should be the embedded jars included by the surefire test classpath as well? If yes: How can you configurate it correctly?