0

我正在尝试使用 Maven 插件 Failsafe 来运行 src/it/java 目录中的集成测试。我正在使用 build-helper 插件来获取我的集成测试资源

我设置了我的故障保护插件,比如......

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

                    <configuration>
                        <printSummary>true</printSummary>
                    </configuration>
                </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>
                                        <directory>src/it/java</directory>
                                    </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>

我也有 Surefire 插件来运行我的单元测试...

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.22.0</version>
        </plugin>

当我执行 mvn clean verify 时,只有单元测试以 surefire 运行并且故障安全不运行,当我尝试 mvn failsafe:verify 时没有运行测试,当我尝试 mvn build-helper:add-test-sources failsafe:verify 时,它抛出无法找到测试源的错误。

[ERROR] Failed to execute goal org.codehaus.mojo:build-helper-maven-plugin:3.0.0:add-test-source (default-cli) on project stkweb: The parameters 'sources' for goal org.codehaus.mojo:build-helper-maven-plugin:3.0.0:add-test-source are missing or invalid -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginParameterException

现在,如果我稍微改变一下配置,并将我的集成测试放在 src/test/java 文件夹中,它可以很好地运行它们。只是出于设计原因,我们希望它们位于单独的目录中。

4

1 回答 1

0

问题归结为使用<pluginManagement>标签。

<build>
  <pluginManagement>
    <plugins>
    </plugins>
  </pluginManagement>
</build>

当我删除 pluginManagement 标记时,它开始运行 FailSafe。

<build>
  <plugins>
  </plugins>
</build>

这也解决了我们与 Jacoco 的问题,在我们只需要直接致电 Jacoco 之前。

于 2018-08-28T17:08:20.757 回答