Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Maven failsafe没有抱怨指定了不存在的配置文件_Maven_Maven Failsafe Plugin - Fatal编程技术网

Maven failsafe没有抱怨指定了不存在的配置文件

Maven failsafe没有抱怨指定了不存在的配置文件,maven,maven-failsafe-plugin,Maven,Maven Failsafe Plugin,我的pom中有两个配置文件: <profiles> <profile> <id>functional-tests</id> <build> <plugins> <plugin> <artifactId>maven-fa

我的pom中有两个配置文件:

 <profiles>
        <profile>
            <id>functional-tests</id>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <configuration>
                            <testSourceDirectory>test/test-functional/java</testSourceDirectory>
                            <includes>
                                <include>**/*FT.java</include>
                            </includes>
                        </configuration>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>integration-test</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>it-tests</id>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <configuration>
                            <testSourceDirectory>test/test-it/java</testSourceDirectory>
                            <includes>
                                <include>**/*IT.java</include>
                            </includes>
                        </configuration>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>integration-test</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        ...
但当我运行这个:

 mvn failsafe:integration-test -PrandomWord
它触发
它测试
配置文件。我想知道为什么,是否有一种方法可以让故障保护插件输出类似于未识别的配置文件

谢谢你的帮助


如果有必要,这里是我的故障保护插件:

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

org.apache.maven.plugins
maven故障保护插件
集成测试

回答您关于它为什么会触发的问题
它会测试
。事实上,它不会激活任何配置文件,因此使用默认插件配置,其中包含列表中的
***it.java
。因此,默认情况下,它运行所有
it
测试

这是一种通过概要文件管理插件执行的奇怪方法。我怀疑是否有一个合理的方法来验证您描述的配置文件名称。我想在此推荐另一种方法

方法1。将
和cli与@ 您可以使用
id
指定两次插件执行,然后执行以下操作:

更新:无需指定
目标
,因为它只与生命周期相关,我们还是在命令行中键入它

方法2。使用
和属性 将这两个执行作为生命周期的一部分,但通过提供跳过标志来控制执行。即,定义两个属性,例如
skip.tests.it=true
skip.tests.ft=true
,并将
${skip.tests.ft}
添加到相关配置部分。那你就可以这么做了

# run with no tests by default
mvn verify 

# run with only FT
mvn verify -Dskip.tests.ft=false 

# run with all tests
mvn verify -Dskip.tests.ft=false -Dskip.tests.it=false

将整个生命周期与所需的测试一起运行。

如果调用插件的目标
:集成测试或类似测试,则不会启动生命周期。我建议开始一个生命周期,比如
mvn verify-P..
,因为您还定义了maven failsafe插件的目标
verify
,该目标绑定到验证周期,该周期将不会调用…此外,使用
*IT的include配置。java
是maven failsafe pluginI中的默认设置,删除了验证目标。我不希望这些测试集成为生命周期的一部分,相反,我希望单独运行它们并按需运行。谢谢您的回答。也许我应该多讲一点背景。我之所以使用配置文件,是因为我想从maven默认生命周期中排除所有IT和FT,也就是说,我想在单独的maven目标中按需运行IT和FT。@JoãoMatos您错过了我在代码段中关于如何使用
none
将此执行与默认生命周期分离的评论。我只为英国《金融时报》做了这件事,但你们两个都可以。
 <plugin>
    <artifactId>maven-failsafe-plugin</artifactId>
    <executions>
        <execution>
            <id>it-tests</id>
            <phase>none</phase> <!-- detach this execution from default lifecycle -->
            <configuration>
                <testSourceDirectory>test/test-it/java</testSourceDirectory>
                <includes>
                    <include>**/*IT.java</include>
                </includes>
            </configuration>
        </execution>
        <execution>
            <id>functional-tests</id>
            <phase>none</phase> <!-- detach this execution from default lifecycle -->
            <configuration>
                <testSourceDirectory>test/test-ft/java</testSourceDirectory>
                <includes>
                    <include>**/*FT.java</include>
                </includes>
            </configuration>
        </execution>
    </executions>
</plugin>
mvn failsafe:integration-test@it-tests
mvn failsafe:integration-test@functional-tests
# run with no tests by default
mvn verify 

# run with only FT
mvn verify -Dskip.tests.ft=false 

# run with all tests
mvn verify -Dskip.tests.ft=false -Dskip.tests.it=false