gpt4 book ai didi

maven - Thorntail没有运行以进行集成测试,但是我有一个正在运行的项目相同的pom.xml

转载 作者:行者123 更新时间:2023-12-02 10:57:43 30 4
gpt4 key购买 nike

整个下午,我一直在努力解决有关错误的神秘问题:

[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)

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

对于工作示例,我有一些不错的 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

这是我的“哑”测试文件:
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阶段运行单元测试)可识别称为*Test的类。 Maven Failsafe插件(负责在integration-test阶段运行集成测试)可识别称为*IT的类。

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

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

关于maven - Thorntail没有运行以进行集成测试,但是我有一个正在运行的项目相同的pom.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56244941/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com