7

I have added the following plugin in the pom.xml

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.18.1</version>
    <configuration>
        <includes>
            <include>**/IT*.java</include>
        </includes>
        <testSourceDirectory>${basedir}/src/integration-test/java</testSourceDirectory>
        <testClassesDirectory>${project.build.directory}/it-classes</testClassesDirectory>
    </configuration>
    <executions>
        <execution>
            <id>integration-test</id>
            <goals>
                <goal>integration-test</goal>
                <goal>verify</goal>
            </goals>
        </execution>
    </executions>
 </plugin>

And I have a test under the directory src\integration-test\java called ITSample.java with @Test annotations.

Maven reports

[DEBUG]   (s) skip = false
[DEBUG]   (s) skipITs = false
[DEBUG]   (s) skipTests = false
[DEBUG]   (s) testSourceDirectory = ...\src\integration-test\java
[DEBUG]   (s) testClassesDirectory = ...\target\it-classes
[DEBUG]   (s) includes = [**/IT*.java]

Which seem as intended, but when I run mvn failsafe:integration-test I get back from maven:

[INFO] No tests to run.

Any ideas if I am missing anything or I should set up something differently?

One more thing I noticed is that when I run mvn integration-test the failsafe plugin is not executed.

Tunaki
  • 132,869
  • 46
  • 340
  • 423
andreadi
  • 1,953
  • 1
  • 20
  • 35
  • Can you move you integration tests to the same source directory as your JUnit cases (i.e inside `src/test/java`) and then try running `mvn clean install`? Post back the results. – Saif Asif Sep 29 '15 at 10:17
  • What `testSourceDirectory` do you have configured in your `pom.xml` file? If it doesn't match what you've configured against the failsafe plugin, that could be the issue. Also, the `testSourceDirectory` and `testClassesDirectory` options aren't required as part of the failsafe plugin's configuration. Usually when things aren't working a good way to troubleshoot is to remove all non-essential config options and try to get the most basic example possible working, and then (slowly) reconfigure from there. – aroth Sep 29 '15 at 10:38
  • I moved the test to src/test/java and removed the references to the testSourceDirectories. Now when I `mvn clean install` no tests are run. However when I run `mvn failsafe:integration-test` the test runs. – andreadi Sep 29 '15 at 12:21
  • Have you defined the definition of maven-failsafe-plugin by coincidence in a pluginManagement ? – khmarbaise Sep 29 '15 at 12:26
  • @khmarbaise I searched the whole project the only reference of failsafe is in the parent pom.xml that I pasted. – andreadi Sep 29 '15 at 12:39
  • Does [this answer](http://stackoverflow.com/a/9949341/944849) help? – user944849 Sep 29 '15 at 13:24

1 Answers1

1

I am using the build-helper-maven-plugin to move my integration tests to a different folder:

        <plugin>                                                             
            <groupId>org.codehaus.mojo</groupId>                             
            <artifactId>build-helper-maven-plugin</artifactId>               
            <executions>                                                     
                <execution>                                                  
                    <id>add-source</id>                                      
                    <phase>generate-sources</phase>                          
                    <goals>                                                  
                        <goal>add-test-source</goal>                         
                    </goals>                                                 
                    <configuration>                                          
                        <sources>                                            
                            <source>src/it/java</source>                     
                        </sources>                                           
                    </configuration>                                         
                </execution>                                                 
                <execution>                                                  
                    <id>add-resource</id>                                    
                    <phase>generate-sources</phase>                          
                    <goals>                                                  
                        <goal>add-test-resource</goal>                       
                    </goals>                                                 
                    <configuration>                                          
                        <resources>                                          
                            <resource>                                       
                                <directory>src/it/resources</directory>      
                            </resource>                                      
                        </resources>                                         
                    </configuration>                                         
                </execution>                                                 
            </executions>                                                    
        </plugin>

The failsafe plugin I just include like this:

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

        </plugin>                   
Matthias Wimmer
  • 3,789
  • 2
  • 22
  • 41