maven:使用 junit 4 执行集成测试,覆盖父 pom 中的设置

maven: execute integration tests with junit 4, overriding settings in parent pom

我已经迁移到 JUnit 5。在我的集成测试中,我使用的是 PowerMock,不幸的是它还不支持最新的 JUnit 版本(参见 https://github.com/powermock/powermock/issues/830)。因此,我决定 运行 使用较新版本进行单元测试,该版本在父 POM 中定义为默认版本,并且仅针对 JUnit 4 进行 运行 集成测试。我试图覆盖子插件中的插件POM 但测试不会执行,可能是因为测试未被识别为 JUnit 4 测试,因此 maven-failsafe-plugin 找不到要执行的任何集成测试。

父 POM:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>3.0.0-M4</version>
            <executions>
                <execution>
                    <id>integration-tests</id>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>
                    <configuration>
                        <argLine>${failsafeOverridableArgLine}
                            -Djacoco-agent.destfile=${project.build.directory}/coverage-reports/jacoco-it.exec</argLine>
                        <skipTests>${skip.integration.tests}</skipTests>
                        <includes>
                            <include>**/*IntegrationTest.java</include>
                        </includes>
                    </configuration>
                </execution>
            </executions>
        </plugin>
      ...
      <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter</artifactId>
        <version>5.5.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>5.5.2</version>
        <scope>test</scope>
    </dependency>

子 POM:

       <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>3.0.0-M4</version>
            <executions>
                <execution>
                    <id>integration-tests</id>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>
                    <configuration combine.self="override">
                        <argLine>${failsafeOverridableArgLine}
                            -Djacoco-agent.destfile=${project.build.directory}/coverage-reports/jacoco-it.exec</argLine>
                        <skipTests>${skip.integration.tests}</skipTests>
                        <includes>
                            <include>**/*IntegrationTest.java</include>
                        </includes>
                        <classpathDependencyExcludes>
                            <classpathDependencyExclude>org.junit.jupiter:junit-jupiter</classpathDependencyExclude>
                            <classpathDependencyExclude>org.junit.jupiter:junit-jupiter-engine</classpathDependencyExclude>
                        </classpathDependencyExcludes>
                        <additionalClasspathElements>
                            <additionalClasspathElement>${settings.localRepository}/junit/junit/4.12/junit-4.12.jar</additionalClasspathElement>
                        </additionalClasspathElements>
                    </configuration>
                </execution>
            </executions>
        </plugin>

这个配置正确吗?

问题已解决我需要将以下依赖项添加到覆盖插件中:

          <dependencies>
                <dependency>
                    <groupId>org.apache.maven.surefire</groupId>
                    <artifactId>surefire-api</artifactId>
                    <version>3.0.0-M4</version>
                </dependency>
                <dependency>
                    <groupId>org.apache.maven.surefire</groupId>
                    <artifactId>surefire-junit47</artifactId>
                    <version>3.0.0-M4</version>
                </dependency>
            </dependencies>

现在集成测试 运行 使用 junit4 而单元测试 运行w 使用 junit5