java集成测试在升级failsafe时失败,但在intellij中通过

bihw5rsg  于 2021-07-06  发布在  Java
关注(0)|答案(1)|浏览(410)

我有一个多maven模块项目。项目运行良好,一切都通过了,但是如果我将failsafe plugin从2.22.2升级到最新版本3.0.0-m5,那么maven模块中的两个模块(客户端和带有jersey的服务器)的集成测试就会失败。我尝试过不同的配置,但我不太确定该怎么做了。。。所以我希望有人能解释我做错了什么。。。
项目可在以下位置找到: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的想法里运行它,它就会过去,但是 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
yduiuuwa

yduiuuwa1#

也许你应该尝试一下临时的解决方法。
让我们从调查问题开始。启用调试日志并运行测试

mvn -X verify

并研究控制台上打印的类路径。
我注意到您正在使用maven shade插件来修改jar文件的内容。我想问题可能出在类路径上。我们更改了maven failsafe插件,以便类路径包含指向附加的主jar的路径。在另一个站点上,maven surefire插件使用target/类。failsafe插件用于集成测试,并使用jar文件,这是测试应用程序的更实际的方法。

相关问题