3
votes

I am working on a maven based project. Project has multiple modules. Here is the project structure

-- Project

--Module1  
   -- pom.xml  
--Module2  
   -- pom.xml    
--Module3-war   
   -- pom.xml 
--parent module   
   --pom.xml

Parent module packaging type is "pom" and all the modules are defined in this.
I added the failsafe-pligin in parent module pom as shown below

 <build>
            <plugins>
               <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <executions>
                  <execution>
                    <id>integration-test</id>
                    <phase>integration-test</phase>
                    <goals>
                      <goal>integration-test</goal>
                    </goals>
                  </execution>
                  <execution>
                    <id>verify</id>
                    <phase>verify</phase>
                    <goals>
                      <goal>verify</goal>
                    </goals>
                  </execution>
                </executions>
            </plugin>
         </plugins>
      </build>

Now when I am running the "mvn verify" command, failsafe plugin is not getting executed. My Integration test name "TestServiceIT.java" is in module1 in the structure.

When I added the same "failsafe" plugin in my war module then I see that failsafe plugin get executed after creating the WAR but it could not find the test class. See below

[INFO] Started Jetty Server
[INFO]
[INFO] --- maven-failsafe-plugin:2.15:integration-test (integration-test) @ service-integration-test
---
[INFO] No tests to run.
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform d
endent!
[INFO]
[INFO] --- jetty-maven-plugin:8.1.11.v20130520:stop (stop-jetty) @ service-integration-test ---
[INFO]
[INFO] --- maven-failsafe-plugin:2.15:verify (verify) @ service-integration-test ---
[INFO] No tests to run.

So, my questions are

  1. When failsafe plugin is defined in main pom.xml then why it's not getting executed?
  2. Why it's not able to find testcases defined in another module?
  3. What is the best practice for writing the integration test in multi module maven project?
1
Do you found a solution for this?FranAguiar
Somehow failsafe plugin didn't work for me in multi module project. Failsafe plugin always looks for test under that project and in the sub modules.Jha
My solution was to create the new module "integration-test" and add all the tests in this module. Add this module in parent pom so that at the end it runs and validate your integration test.<plugins><plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId> <version>2.19.1</version> <configuration> <includes> <include>*.IT/*.java</include> </includes> </configuration> </plugin> </plugins>Jha

1 Answers

0
votes

I think you have to add dependenciesToScan in failsafe plugin configuration. ie:

 <dependencies>
  <dependency>
   <groupId>org.arquillian.tck.container</groupId>
   <artifactId>arquillian-tck-container</artifactId>
   <version>1.0.0.Final-SNAPSHOT</version>
   <classifier>tests</classifier>
  </dependency>
  </dependencies>
 <build>
  <plugins>
   <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.14-SNAPSHOT</version>
    <configuration>
     <dependenciesToScan>
      <dependency>org.arquillian.tck.container:arquillian-tck-container</dependency>
     </dependenciesToScan>
    </configuration>
   </plugin>
  </plugins>
 </build>

But I cannot test it because of this bug https://issues.apache.org/jira/browse/SUREFIRE-1024