Java Maven集成测试和具有概要文件的单元测试

Java Maven集成测试和具有概要文件的单元测试,java,maven,unit-testing,Java,Maven,Unit Testing,我想知道为什么它不能正常工作。我想有itTest profle,它将通过Maven启动集成(故障保护插件)和单元(surefire插件)。 我的配置: <plugins> <plugin> <artifactId>maven-surefire-plugin</artifactId> <configuration> <skip>${unit

我想知道为什么它不能正常工作。我想有itTest profle,它将通过Maven启动集成(故障保护插件)和单元(surefire插件)。 我的配置:

<plugins>
    <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <skip>${unit-tests.skip}</skip>
                <excludes>
                    <exclude>**/*IT.java</exclude>
                </excludes>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>
                    <configuration>
                        <skip>${integration-tests.skip}</skip>
                        <includes>
                            <include>**/*IT.java</include>
                        </includes>
                    </configuration>
                </execution>
            </executions>
        </plugin>
</plugins>

maven surefire插件
${unit tests.skip}
**/*IT.java
maven故障保护插件
集成测试
验证
${integration tests.skip}
**/*IT.java
侧面图

<profile>
        <id>itTest</id>
        <properties>
            <propFile>profiles/itTest.properties</propFile>
            <spring.profile>itTest</spring.profile>
            <integration-tests.skip>false</integration-tests.skip>
            <unit-tests.skip>false</unit-tests.skip>
        </properties>
    </profile>

伊特斯特
配置文件/测试属性
伊特斯特
假的
假的

结果:两个测试都被跳过。。。即使我更改配置文件或硬编码跳转为false,它仍然不起作用。

我不知道为什么您的配置没有执行您希望它执行的操作(可能与属性的求值顺序有关,因此当您重置属性时,属性已被求值),但通常的处理方法是将整个插件配置放入配置文件中。

而不是将两个插件都作为默认插件放入并尝试跳过它们,我认为您可以简单地在配置文件中声明插件本身。 即


伊特斯特
maven故障保护插件
集成测试
验证
**/*IT.java

首先,maven surefire插件中的排除只是多余的,因为它是maven surefire插件中的默认值。包含在maven failsave插件中也是多余的,因为它是maven failsave插件中的默认插件…您是否确实使用
mvn-P itTest
激活了配置文件?是,我是通过Intellij接口来实现的,在这里我声明profile和command,其中command是verify,但是如果我为它更改true,那么单元测试也可能是另一个类似install的命令,如果同时删除
excludes
includes
块会发生什么?没有任何变化,但我发现了有趣的事情。当我使用硬编码值运行
clean install
时,例如false/true测试是否正在运行,但是当涉及到使用任何配置文件时,它们都会被跳过是的,这可能是解决方案,但id不能满足我的要求,我希望有全局插件,其他配置文件可以使用它(因此我声明变量来管理surefire和failsafe)你能详细阐述一下你的想法和它应该是什么样子吗?好的,我试试。假设我有3个配置文件和这些变量(unit test.skip,integration test.skip),现在只有itTest将运行这两个测试,但在将来,我希望变得灵活,如果我想用我的1个配置文件运行单元测试,我只需要在这个特定配置文件中将变量从false更改为true。这就是为什么我不想把它拉到最简档的原因。
<profile>
    <id>itTest</id>
    <plugins>
      <plugin>
        <artifactId>maven-failsafe-plugin</artifactId>
        <executions>
            <execution>
                <goals>
                    <goal>integration-test</goal>
                    <goal>verify</goal>
                </goals>
                <configuration>
                    <includes>
                        <include>**/*IT.java</include>
                    </includes>
                </configuration>
            </execution>
        </executions>
      </plugin>
    <plugins>