gpt4 book ai didi

java - Arquillian 测试在本地服务器中运行,而不是在远程 Wildfly 服务器中运行

转载 作者:行者123 更新时间:2023-12-04 20:44:53 24 4
gpt4 key购买 nike

我正在尝试使用 arquillian 框架测试我的应用程序。所以我配置了 pom 和 arquillian.xml 以在 wildfly 远程容器中运行我的测试用例。即使我在 arquillian.xml 中给出了远程地址,测试用例也在本地 wildfly 服务器中运行。我已配置服务器配置文件并使用 remote-wildfly 服务器配置文件运行测试。

测试类

@RunWith(Arquillian.class)
public class BasicTest {

@Deployment
public static JavaArchive createDeployment() {
return ShrinkWrap.create(JavaArchive.class).addClass(Greeter.class)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}

@Inject
private Greeter greeter;

@Test
public void shouldBeAbleTo() {
assertEquals("Hello, aliens!", greeter.createGreeting("aliens"));
}

pom.xml

<?xml version="1.0"?>
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>org.jboss.aerogear</groupId>
<artifactId>arquillian-wildfly-example</artifactId>
<packaging>jar</packaging>
<version>0.0.1</version>


<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<version.org.jboss.arquillian>1.1.5.Final</version.org.jboss.arquillian>
<version.org.wildfly>8.1.0.Final</version.org.wildfly>
<version.junit>4.11</version.junit>
</properties>

<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
</plugin>
<!--This plugin's configuration is used to store Eclipse m2e settings
only. It has no influence on the Maven build itself. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-dependency-plugin
</artifactId>
<versionRange>
[2.1,)
</versionRange>
<goals>
<goal>unpack</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>

<dependencyManagement>
<dependencies>

<!-- Arquillian BOM (Bill Of Materials). -->
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>${version.org.jboss.arquillian}</version>
<scope>import</scope>
<type>pom</type>
</dependency>

<!-- JUnit regression testing framework. -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${version.junit}</version>
</dependency>

</dependencies>
</dependencyManagement>

<profiles>

<!-- Arquillian WildFly remote profile -->
<profile>
<id>arq-widlfly-remote</id>
<dependencies>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-arquillian-container-remote</artifactId>
<version>8.2.0.Final</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
</profiles>


<dependencies>

<!-- JUnit regression testing framework. -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>

<!-- JUnit Container Implementation for the Arquillian Project -->
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jboss.arquillian.protocol</groupId>
<artifactId>arquillian-protocol-servlet</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

arquillian.xml

<arquillian xmlns="http://jboss.org/schema/arquillian" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://jboss.org/schema/arquillian
http://jboss.org/schema/arquillian/arquillian_1_0.xsd">

<!-- Sets the protocol which is how Arquillian talks and executes the tests inside the container -->
<defaultProtocol type="Servlet 3.0" />

<!-- Configuration to be used when the WidlFly remote profile is active -->
<container qualifier="widlfly-remote">
<configuration>
<property name="managementAddress">xxxxx</property>
<property name="managementPort">xxxx</property>
<property name="username">xxxx</property>
<property name="password">xxxx</property>
</configuration>
</container>

但是测试用例运行在 127.0.0.1:9990 wildfly 服务器上,而不是运行在我在 arquillian.xml 中指定的远程 wildfly 服务器上。我必须做/改变什么配置。请帮助我。

最佳答案

您需要告诉 Arquillian 您想要运行哪个 arquillian.xml 容器限定符,因为您可以在同一个 xml 文件中定义多个。如果你只有一个元素并且永远只需要一个,你可以在它上面定义 default=true 属性,在这种情况下 Arquillian 将使用它,除非定义了其他任何东西。

<container qualifier="widlfly-remote" default="true">
...
</container>

否则,您可以在 Maven Surefire 执行中将 -Darquillian.launch=widlfly-remote 定义为系统属性以动态设置它。

本质上,在您当前的设置中,您没有告诉 Arquillian 使用哪个限定符,这意味着它将以您在类路径上的容器适配器的默认值运行(这就是为什么您看到 127.0.0.1 被使用.).

关于java - Arquillian 测试在本地服务器中运行,而不是在远程 Wildfly 服务器中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30479366/

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