7 Replies Latest reply on Jan 21, 2010 1:20 PM by pgmjsd

    Trying out the full classpath example

    pgmjsd

      I was able to spend some time trying out the 'full classpath' Maven example in the past few days.  I ran into a snag though.   The surefire plugin configuration specifies -Djboss.home=${JBOSS_HOME}, but my start up code thinks the system property is not set.   I tried running my example test inside my IDE, specifying -Djboss.home and it worked fine.

       

      Why isn't surefire paying attention to the <argLine>?

        • 1. Re: Trying out the full classpath example
          alrubinger
          Just so we can be sure, print the relevant output from Maven using "-X"?
          • 2. Re: Trying out the full classpath example
            pgmjsd
            Hang on, I think it's trying to run the code in the 'test' phase instead of the 'integration-test' phase.   Maven... feh.
            • 3. Re: Trying out the full classpath example
              pgmjsd

              That's it.... Maven is running the 'test' phase first.   That uses the default surefire config which has no <argLine>.

               

              I have two unit tests in two packages:

              • eg.test.unit - Regular unit test.   Should run during the 'test' phase.
              • eg.test.integration - Embedded tests.   Should run only during the 'integration-test' phase.

               

              I thought this would work:

               

                          <plugin>

                              <artifactId>maven-surefire-plugin</artifactId>

                              <executions>

                                  <execution>

                                      <id>test</id>

                                      <phase>test</phase>

                                      <goals><goal>test</goal></goals>

                                      <configuration>

                                          <includes>

                                              <include>**/test/unit/*Test.java</include>

                                          </includes>

                                      </configuration>                       

                                  </execution>

                                  <execution>

                                      <id>integration-test</id>

                                      <phase>integration-test</phase>

                                      <goals>

                                          <goal>test</goal>

                                      </goals>

                                      <configuration>

                                          <additionalClasspathElements>

                                              <additionalClasspathElement>${JBOSS_HOME}/client/jbossws-native-client.jar

                                              </additionalClasspathElement>

                                          </additionalClasspathElements>

                                          <redirectTestOutputToFile>true</redirectTestOutputToFile>

                                          <trimStackTrace>false</trimStackTrace>

                                          <printSummary>true</printSummary>

                                          <includes>

                                              <include>**/test/integration/*Test.java</include>

                                          </includes>

                                          <forkMode>always</forkMode>

                                          <!--

                                            MaxPermSize Required to bump the space for relective

                                            data like classes, methods, etc. EMB-41, EMB-74. Endorsed

                                            required for things like WS support (EMB-61)

                                          -->

                                          <argLine>-Xmx512m -XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=true -Djava.endorsed.dirs=${JBOSS_HOME}/lib/endorsed -Djboss.home=${JBOSS_HOME}</argLine>

                                      </configuration>

                                  </execution>

                              </executions>

                          </plugin>

              • 4. Re: Trying out the full classpath example
                alrubinger

                So all set?

                 

                S,

                ALR

                • 5. Re: Trying out the full classpath example
                  pgmjsd

                  Nope.  The surefire plugin either runs the integration test as a unit test, or it runs no tests whatsoever.   Might be because I'm using TestNG rather than JUnit though.

                  • 6. Re: Trying out the full classpath example
                    alrubinger

                    You can have Surefire run in both phases, but you need to configure the 2nd phase as a profile.

                     

                    For example:

                     

                    http://anonsvn.jboss.org/repos/jbossas/projects/ejb-book/trunk/ch08-statusupdate/pom.xml

                     

                    That one above inherits the regular unit tests "test" phase from ../build/pom.xml, and also defines the integration-test one in the "it" profile.  To get it to run automatically remember to set "activeByDefault".

                     

                    S,

                    ALR

                    • 7. Re: Trying out the full classpath example
                      pgmjsd

                      Okay, tried the profile approach.   I made two TestNG groups: 'unit-test' and 'integration-test' and specified the unit-test group in the main surefire plugin config and integration-test in the 'it' profile config.  When I do 'mvn install' it runs the unit tests like I expect.  Then it unpacks JBoss AS, tries to run the integration tests but doesn't actually do anything.  Grrr.


                          <profiles>

                              <profile>

                                  <id>it</id>

                                  <activation>

                                      <activeByDefault>true</activeByDefault>

                                  </activation>

                                  <build>

                                      <plugins>

                                          <!-- Get AS and put into "target" -->

                                          <plugin>

                                              <groupId>org.apache.maven.plugins</groupId>

                                              <artifactId>maven-dependency-plugin</artifactId>

                                              <executions>

                                                  <execution>

                                                      <id>unpack</id>

                                                      <phase>pre-integration-test</phase>

                                                      <!-- So run before testing -->

                                                      <goals>

                                                          <goal>unpack</goal>

                                                      </goals>

                                                      <configuration>

                                                          <artifactItems>

                                                              <artifactItem>

                                                                  <groupId>org.jboss.jbossas</groupId>

                                                                  <artifactId>jboss-as-distribution</artifactId>

                                                                  <version>${version.org.jboss.jbossas}</version>

                                                                  <type>zip</type>

                                                                  <overWrite>false</overWrite>

                                                                  <outputDirectory>${project.build.directory}</outputDirectory>

                                                              </artifactItem>

                                                          </artifactItems>

                                                      </configuration>

                                                  </execution>

                                              </executions>

                                          </plugin>

                                          <plugin>

                                              <artifactId>maven-surefire-plugin</artifactId>

                                              <executions>

                                                  <execution>

                                                      <id>integration-test</id>

                                                      <phase>integration-test</phase>

                                                      <goals>

                                                          <goal>test</goal>

                                                      </goals>

                                                      <configuration>

                                                          <excludedGroups>unit-test</excludedGroups>

                                                          <groups>integration-test</groups>

                                                          <additionalClasspathElements>

                                                              <additionalClasspathElement>${JBOSS_HOME}/client/jbossws-native-client.jar

                                                              </additionalClasspathElement>

                                                          </additionalClasspathElements>

                                                          <redirectTestOutputToFile>true</redirectTestOutputToFile>

                                                          <trimStackTrace>false</trimStackTrace>

                                                          <printSummary>true</printSummary>

                                                          <forkMode>always</forkMode>

                                                          <!--

                                                            MaxPermSize Required to bump the space for relective

                                                            data like classes, methods, etc. EMB-41, EMB-74. Endorsed

                                                            required for things like WS support (EMB-61)

                                                          -->

                                                          <argLine>-Xmx512m -XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=true

                                                              -Djava.endorsed.dirs=${JBOSS_HOME}/lib/endorsed -Djboss.home=${JBOSS_HOME}

                                                          </argLine>

                                                      </configuration>

                                                  </execution>

                                              </executions>

                                          </plugin>

                                      </plugins>

                                  </build>

                              </profile>

                          </profiles>

                          <build>

                              <plugins>

                                  <plugin>

                                      <groupId>org.apache.maven.plugins</groupId>

                                      <artifactId>maven-compiler-plugin</artifactId>

                                      <configuration>

                                          <source>${compileSource}</source>

                                          <target>${compileSource}</target>

                                      </configuration>

                                  </plugin>

                                  <plugin>

                                      <artifactId>maven-surefire-plugin</artifactId>

                                      <configuration>

                                          <excludedGroups>integration-test</excludedGroups>

                                          <groups>unit-test</groups>

                                      </configuration>

                                  </plugin>

                              </plugins>

                          </build>