繁体   English   中英

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

[英]Integration test fails when upgrading failsafe but passes within intellij

我有一个多 maven 模块项目。 该项目运行良好,一切都通过了,但如果我将故障安全插件从 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

也许您应该尝试使用临时解决方法

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

mvn -X verify

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM