Thorntail 不是 运行 用于集成测试,但我有相同的 pom.xml 工作项目

Thorntail not running for integration testing but I have the same pom.xml of a working project

整个下午我都在尝试解决一个关于错误的神秘问题:

[ERROR] Tests run: 3, Failures: 0, Errors: 3, Skipped: 0, Time elapsed: 9.783 s <<< FAILURE! - in api.rest.AdRestServiceTest
[ERROR] testGet  Time elapsed: 4.351 s  <<< ERROR!
java.net.ConnectException: Connection refused: connect
        at api.rest.AdRestServiceTest.testGet(AdRestServiceTest.java:32)

[ERROR] testCount  Time elapsed: 2.013 s  <<< ERROR!
java.net.ConnectException: Connection refused: connect
        at api.rest.AdRestServiceTest.testCount(AdRestServiceTest.java:27)

[ERROR] testGetAll  Time elapsed: 2.022 s  <<< ERROR!
java.net.ConnectException: Connection refused: connect
        at api.rest.AdRestServiceTest.testGetAll(AdRestServiceTest.java:21)

我可以 运行 一个工作项目 (https://github.com/hostettler/microservices/tree/integration_tests) mvn clean install

我有一些不错的 Thorntail is ready 作为工作示例。

2019-05-21 16:29:26,235 INFO  [org.wildfly.swarm] (main) THORN99999: Thorntail is Ready
[INFO]
[INFO] --- jacoco-maven-plugin:0.8.2:prepare-agent (integration-tests-preaparation) @ counterparty-service ---
[INFO] argLineForIntegration set to -javaagent:C:\Users\Admin\.m2\repository\org\jacoco\org.jacoco.agent\0.8.2\org.jacoco.agent-0.8.2-runtime.jar=destfile=C:\Users\Admin\Desktop\ProjetINFO\microservices\counterparty-service\target\jacoco-it.exec
[INFO]
[INFO] --- maven-failsafe-plugin:2.22.1:integration-test (default) @ counterparty-service ---
[INFO]
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running api.CounterpartyRestServiceIT
2019-05-21 16:29:34,220 INFO  [stdout] (default task-1) Hibernate: ...

我刚刚复制了那些 pom.xml(父 pom 和交易对手服务的 pom)但它仍然不起作用..

这是父级 pom.xml :

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>ch.unige</groupId>
    <artifactId>PInfo2</artifactId>
    <version>0.2.0-SNAPSHOT</version>
    <name>Parent Pom of the PInfo2</name>

    <packaging>pom</packaging>

    <!--<scm>
        <url>https://github.com/hostettler/microservices</url>
        <connection>scm:git:git@github.com/hostettler/microservices.git</connection>
        <developerConnection>scm:git:git@github.com/hostettler/microservices</developerConnection>
    </scm> -->

    <properties>
        <version.thorntail>2.3.0.Final</version.thorntail>
        <version.h2>1.4.197</version.h2>
        <failOnMissingWebXml>false</failOnMissingWebXml>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <skip-docker-build>true</skip-docker-build>
        <skip-docker-compose>false</skip-docker-compose>
        <dockerHost>tcp://localhost:2375</dockerHost>
    </properties>


    <modules>
        <module>image-service</module>
        <module>stats-service</module>
        <module>chat-service</module>
        <module>ad-service</module>
        <module>category-service</module>
        <module>user-service</module>
        <module>search-service</module>
        <module>api-gateway</module>
    </modules>


    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>io.thorntail</groupId>
                <artifactId>bom</artifactId>
                <version>${version.thorntail}</version>
                <scope>import</scope>
                <type>pom</type>
            </dependency>
            <!--<dependency>
                <groupId>org.aerogear.kafka</groupId>
                <artifactId>kafka-cdi-extension</artifactId>
                <version>0.1.0</version>
            </dependency> -->
            <dependency>
                <groupId>com.github.dadrus.jpa-unit</groupId>
                <artifactId>jpa-unit-bom</artifactId>
                <version>0.5.0</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>1.18.4</version>
            </dependency>
            <dependency>
                <groupId>javax.enterprise</groupId>
                <artifactId>cdi-api</artifactId>
                <version>1.2</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.jboss.spec.javax.ws.rs</groupId>
                <artifactId>jboss-jaxrs-api_2.0_spec</artifactId>
                <version>1.0.0.Final</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>com.h2database</groupId>
                <artifactId>h2</artifactId>
                <version>${version.h2}</version>
            </dependency>
            <dependency>
                <groupId>org.aerogear.kafka</groupId>
                <artifactId>kafka-cdi-extension</artifactId>
                <version>0.1.0</version>
            </dependency>
            <dependency>
                <groupId>io.thorntail</groupId>
                <artifactId>swagger</artifactId>
                <version>2.2.1.Final</version>
            </dependency>
            <dependency>
                <groupId>org.junit</groupId>
                <artifactId>junit-bom</artifactId>
                <version>5.3.2</version>
                <scope>test</scope>
                <type>pom</type>
            </dependency>
            <!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
            <dependency>
                <groupId>org.junit.jupiter</groupId>
                <artifactId>junit-jupiter-api</artifactId>
                <version>5.3.2</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.junit.jupiter</groupId>
                <artifactId>junit-jupiter-engine</artifactId>
                <version>5.3.2</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.junit.platform</groupId>
                <artifactId>junit-platform-launcher</artifactId>
                <version>1.3.2</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.mockito</groupId>
                <artifactId>mockito-core</artifactId>
                <version>2.23.4</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.mockito</groupId>
                <artifactId>mockito-junit-jupiter</artifactId>
                <version>2.23.4</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>javax.xml.bind</groupId>
                <artifactId>jaxb-api</artifactId>
                <version>2.3.1</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <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.junit.platform</groupId>
            <artifactId>junit-platform-launcher</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-junit-jupiter</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
        </dependency>
    </dependencies>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <artifactId>maven-release-plugin</artifactId>
                    <version>2.5.3</version>
                    <configuration>
                        <autoVersionSubmodules>true</autoVersionSubmodules>
                        <tagNameFormat>@{project.version}</tagNameFormat>
                        <releaseProfiles>release</releaseProfiles>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.0</version>
                    <configuration>
                        <configuration>
                            <source>${maven.compiler.source}</source>
                            <target>${maven.compiler.target}</target>
                        </configuration>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>3.0.0-M3</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-failsafe-plugin</artifactId>
                    <version>3.0.0-M6</version>
                </plugin>

                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>0.8.2</version>
                </plugin>
                <plugin>
                    <groupId>io.thorntail</groupId>
                    <artifactId>thorntail-maven-plugin</artifactId>
                    <version>${version.thorntail}</version>
                </plugin>
                <plugin>
                    <groupId>io.fabric8</groupId>
                    <artifactId>fabric8-maven-plugin</artifactId>
                    <version>4.0.0-M2</version>
                </plugin>
            </plugins>
        </pluginManagement>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>io.thorntail</groupId>
                <artifactId>thorntail-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>package</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>unit-tests</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>integration-tests-preaparation</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                        <configuration>
                            <propertyName>argLineForIntegration</propertyName>                      
                            <destFile>${project.build.directory}/jacoco-it.exec</destFile>
                        </configuration>                        
                    </execution>                    
                    <execution>
                        <id>merge</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>merge</goal>
                        </goals>
                        <configuration>
                            <fileSets>
                                <fileSet>
                                    <directory>${project.build.directory}</directory>
                                    <includes>
                                        <include>*.exec</include>
                                    </includes>
                                </fileSet>
                            </fileSets>
                            <destFile>${project.build.directory}/jacoco-merged.exec</destFile>
                        </configuration>
                    </execution>
                    <execution>
                        <id>report</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                        <configuration>
                        <dataFile>${project.build.directory}/jacoco-merged.exec</dataFile>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>


    <profiles>
        <profile>
            <id>activate_windows</id>
            <activation>
                <os>
                    <family>unix</family>
                </os>
            </activation>
            <properties>
                <dockerHost>tcp://localhost:2375</dockerHost>
            </properties>
        </profile>
        <profile>
            <id>activation_unix</id>
            <activation>
                <os>
                    <family>unix</family>
                </os>
            </activation>
            <properties>
                <dockerHost>unix:///var/run/docker.sock</dockerHost>
            </properties>
        </profile>
        <profile>
            <id>package-docker-image</id>
            <activation>
                <property>
                    <name>docker-build</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>io.fabric8</groupId>
                        <artifactId>fabric8-maven-plugin</artifactId>
                        <configuration>
                            <skip>${skip-docker-build}</skip>
                            <useColor>true</useColor>
                            <dockerHost>${dockerHost}</dockerHost>
                            <images>
                                <image>
                                    <name>%g/%a:%l</name>
                                    <run>
                                        <ports>
                                            <port>8080:8080</port>
                                        </ports>
                                    </run>
                                    <build>
                                        <from>java:openjdk-8-jdk</from>
                                        <ports>
                                            <port>8080</port>
                                        </ports>
                                        <assembly>
                                            <basedir>/</basedir>
                                            <inline>
                                                <files>
                                                    <file>
                                                        <source>${project.build.directory}/${project.build.finalName}-thorntail.jar</source>
                                                        <outputDirectory>/opt</outputDirectory>
                                                    </file>
                                                </files>
                                            </inline>
                                        </assembly>
                                        <entryPoint>
                                            <shell>java -Djava.net.preferIPv4Stack=true -jar \
                                                /opt/${project.build.finalName}-thorntail.jar</shell>
                                        </entryPoint>
                                    </build>
                                </image>
                            </images>
                        </configuration>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <goals>
                                    <goal>build</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

</project>

这是位于广告服务(我们项目的微服务)中的 pom.xml:

<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>ch.unige</groupId>
        <artifactId>PInfo2</artifactId>
        <version>0.2.0-SNAPSHOT</version>
    </parent>

    <artifactId>ad-service</artifactId>
    <name>Ad Service</name>
    <packaging>war</packaging>

    <properties>
        <skip-docker-build>false</skip-docker-build>
    </properties>

    <dependencies>
        <dependency>
            <groupId>io.thorntail</groupId>
            <artifactId>jaxrs</artifactId>
        </dependency>

        <dependency>
            <groupId>io.thorntail</groupId>
            <artifactId>jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>io.thorntail</groupId>
            <artifactId>swagger</artifactId>
        </dependency>
        <dependency>
            <groupId>io.thorntail</groupId>
            <artifactId>cdi</artifactId>
        </dependency>
        <dependency>
            <groupId>io.thorntail</groupId>
            <artifactId>transactions</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.enterprise</groupId>
            <artifactId>cdi-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.jboss.spec.javax.ws.rs</groupId>
            <artifactId>jboss-jaxrs-api_2.0_spec</artifactId>
        </dependency>
        <dependency>
            <groupId>io.thorntail</groupId>
            <artifactId>datasources</artifactId>
        </dependency>
        <dependency>
            <groupId>io.thorntail</groupId>
            <artifactId>logging</artifactId>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>42.2.5</version>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>7.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>5.0.10.Final</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.aerogear.kafka</groupId>
            <artifactId>kafka-cdi-extension</artifactId>
        </dependency>

        <dependency>
            <groupId>com.github.dadrus.jpa-unit</groupId>
            <artifactId>jpa-unit5</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.github.dadrus.jpa-unit</groupId>
            <artifactId>jpa-unit-rdbms</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>rest-assured</artifactId>
            <version>3.3.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-all</artifactId>
            <version>1.3</version>
            <scope>test</scope>
        </dependency>

    </dependencies>



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

            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>unit-tests-1</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                        <configuration>
                        <destFile>jacoco.exec</destFile>
                        </configuration>
                    </execution>
                    <execution>
                        <id>unit-tests-2</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                        <configuration>
                            <append>false</append>
                        </configuration>
                    </execution>                    
                    <execution>
                        <id>report</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>io.thorntail</groupId>
                <artifactId>thorntail-maven-plugin</artifactId>
                <configuration>
                    <!--PLACEHOLDER:configuration -->
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>package</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>start</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>start</goal>
                        </goals>
                        <configuration>
                        <jvmArguments>${}</jvmArguments>
                            <properties>
                                <thorntail.port.offset>20000</thorntail.port.offset>
                            </properties>
                        </configuration>
                    </execution>
                    <execution>
                        <id>stop</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

它们与工作仓库几乎相同(只是添加了 kafka 依赖项并更改了名称)。 我不知道为什么它不在后台启动服务器进行集成测试,但它会在工作库中启动。

我正在处理的回购是:https://github.com/bigotromain/PInfo2/tree/integration_tests

这是我的 "dumb" 测试文件:

package api.rest;

import static io.restassured.RestAssured.when;
import static org.hamcrest.Matchers.containsString;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import io.restassured.RestAssured;

public class AdRestServiceTest {

    @BeforeAll
    public static void setup() {
        RestAssured.baseURI = "http://localhost:28080/ad";
        RestAssured.port = 8080;
    }

    @Test
    public void testGetAll() {
        when().get("/").then().body(containsString("984500C2EEUEB4A0C629"));

    }

    @Test
    public void testCount() {
        when().get("/count").then().body(containsString("5"));
    }

    @Test
    public void testGet() {
        when().get("/984500C2EEUEB4A0C629").then().body(containsString("984500C2EEUEB4A0C629"));
    }

}

我显然不明白为什么 Thorntail 不启动集成测试..有什么帮助吗?? 谢谢

默认情况下,Maven Surefire 插件(负责 test 阶段的 运行 单元测试)识别 classes 称为 *Test。 Maven Failsafe 插件(负责 integration-test 阶段的 运行 集成测试)识别名为 *IT.

的 classes

您的测试 class 称为 AdRestServiceTest,它将在 test 阶段执行。您希望它在 integration-test 阶段执行,因为 integration-test 阶段被 pre-integration-testpost-integration-test 阶段包围。

因此您需要将 AdRestServiceTest 重命名为 AdRestServiceIT。 (另一种选择是重新配置 Surefire 和 Failsafe 插件。)