Maven Failsafe插件没有找到任何测试用例

时间:2015-09-29 09:48:51

标签: java maven integration-testing maven-failsafe-plugin

我在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>

我在带有@Test注释的名为ITSample.java的src \ integration-test \ java目录下进行测试。

Maven报道

[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]

这似乎是预期的,但是当我运行mvn failsafe时:集成测试我从maven回来了:

[INFO] No tests to run.

任何想法,如果我遗失任何东西或我应该设置不同的东西?

我注意到的另一件事是,当我运行mvn integration-test时,不会执行故障安全插件。

1 个答案:

答案 0 :(得分:-1)

我使用build-helper-maven-plugin将集成测试移到另一个文件夹:

        <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>

故障安全插件我只是这样包含:

        <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>