升级故障安全时集成测试失败但在 intellij 中通过

Integration test fails when upgrading failsafe but passes within intellij

我有一个多 Maven 模块项目。项目 运行 很好,一切都通过了,但是如果我将 failsafe 插件从 2.22.2 升级到最新版本 3.0.0-M5,那么两个 Maven 模块(客户端和带有球衣的服务器)中的集成测试失败。我尝试了不同的配置,但我不太清楚该怎么做......所以我希望有人能解释我可能做错了什么......

项目可以在这里找到:https://github.com/Hakky54/mutual-tls-ssl

这只是一个为不同的客户端和服务器设置 ssl/tls 的教程,所以我需要警告你,如果你 运行 它在本地它会拉很多依赖......

插件配置为:

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

失败模块的pom是:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

    <parent>
        <artifactId>mutual-tls-ssl</artifactId>
        <groupId>nl.altindag</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <artifactId>server-with-jersey</artifactId>
    <packaging>jar</packaging>

    <properties>
        <main-class-server>nl.altindag.server.App</main-class-server>
    </properties>

    <dependencies>
        <dependency>
            <groupId>nl.altindag</groupId>
            <artifactId>shared-server-resources</artifactId>
            <version>${project.version}</version>
        </dependency>

        <dependency>
            <groupId>io.github.hakky54</groupId>
            <artifactId>sslcontext-kickstart</artifactId>
        </dependency>

        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-grizzly2-http</artifactId>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.inject</groupId>
            <artifactId>jersey-hk2</artifactId>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
        </dependency>

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
        </dependency>
        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
        </dependency>
        <dependency>
            <groupId>io.github.hakky54</groupId>
            <artifactId>logcaptor</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${version.maven-surefire-plugin}</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>${version.maven-fail-safe}</version>
                <configuration>
                    <classpathDependencyExcludes>
                        <classpathDependencyExclude>org.slf4j:slf4j-simple</classpathDependencyExclude>
                    </classpathDependencyExcludes>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>${version.exec-maven-plugin}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>java</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <mainClass>${version.maven-shade-plugin}</mainClass>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>${version.maven-shade-plugin}</version>
                <configuration>
                    <finalName>server</finalName>
                    <transformers>
                        <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                            <mainClass>${main-class-server}</mainClass>
                        </transformer>
                    </transformers>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>jacoco</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.jacoco</groupId>
                        <artifactId>jacoco-maven-plugin</artifactId>
                        <version>${version.jacoco-maven-plugin}</version>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

</project>

并且以下集成测试失败:AppIT。但是,如果我在 intellij idea 中 运行 它通过了,但是 mvn clean install 它给了我以下异常:

[ERROR] Tests run: 3, Failures: 3, Errors: 0, Skipped: 0, Time elapsed: 1.971 s <<< FAILURE! - in nl.altindag.server.AppIT
[ERROR] nl.altindag.server.AppIT.startServerWithTwoWayAuthentication  Time elapsed: 1.555 s  <<< FAILURE!
org.opentest4j.AssertionFailedError:

Expecting:
 <"">
to be equal to:
 <"Hello">
but was not.
    at server.with.jersey@1.0-SNAPSHOT/nl.altindag.server.AppIT.startServerWithTwoWayAuthentication(AppIT.java:109)

[ERROR] nl.altindag.server.AppIT.startServerWithoutSecurity  Time elapsed: 0.086 s  <<< FAILURE!
org.opentest4j.AssertionFailedError:

Expecting:
 <"">
to be equal to:
 <"Hello">
but was not.
    at server.with.jersey@1.0-SNAPSHOT/nl.altindag.server.AppIT.startServerWithoutSecurity(AppIT.java:40)

[ERROR] nl.altindag.server.AppIT.startServerWithOneWayAuthentication  Time elapsed: 0.207 s  <<< FAILURE!
org.opentest4j.AssertionFailedError:

Expecting:
 <"">
to be equal to:
 <"Hello">
but was not.
    at server.with.jersey@1.0-SNAPSHOT/nl.altindag.server.AppIT.startServerWithOneWayAuthentication(AppIT.java:74)

[INFO]
[INFO] Results:
[INFO]
[ERROR] Failures:
[ERROR]   AppIT.startServerWithOneWayAuthentication:74
Expecting:
 <"">
to be equal to:
 <"Hello">
but was not.
[ERROR]   AppIT.startServerWithTwoWayAuthentication:109
Expecting:
 <"">
to be equal to:
 <"Hello">
but was not.
[ERROR]   AppIT.startServerWithoutSecurity:40
Expecting:
 <"">
to be equal to:
 <"Hello">
but was not.
[INFO]
[ERROR] Tests run: 3, Failures: 3, Errors: 0, Skipped: 0

也许你应该尝试一下时间workaround

让我们从调查问题开始。启用调试日志和运行 测试

mvn -X verify

并调查打印在控制台上的类路径。

我注意到您正在使用修改 JAR 文件内容的 maven-shade-plugin。我认为问题可能出在类路径上。我们更改了 maven-failsafe-plugin 以便类路径包含指向附加主 JAR 的路径。在对面的站点上,maven-surefire-plugin 使用 target/classes 代替。 Failsafe 插件用于集成测试并使用 JAR 文件,这是测试应用程序的更现实的方法。