java 无法运行 arquillian 测试
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7341308/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot run arquillian tests
提问by Pablo
I'm trying to use Arquillian for some unit tests, however I can't find why they fail when deployed using Maven.
我正在尝试使用 Arquillian 进行一些单元测试,但是我无法找到使用 Maven 部署时它们失败的原因。
This is the class test:
这是课堂测试:
package com.ndeveloper.spec.test;
import javax.inject.Inject;
import junit.framework.Assert;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ArchivePaths;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.ByteArrayAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import com.ndeveloper.spec.controller.GreetingBean;
@RunWith(Arquillian.class)
public class GreetingBeanTest {
@Inject
GreetingBean greetingBean;
@Deployment
public static JavaArchive createTestArchive()
{
return ShrinkWrap.create( JavaArchive.class,"test.jar").
addClass(GreetingBean.class).addAsManifestResource(
new ByteArrayAsset("<beans/>".getBytes()),
ArchivePaths.create("beans.xml"));
}
@Test
public void testInjection(){
Assert.assertEquals("Hello World", greetingBean.getGreeting());
}
}
And I'm using the jboss jboss-javaee6-webapp archetype. What's strange is that originally the test worked fine... However after using several times them. The following error started to appear:
我正在使用 jboss jboss-javaee6-webapp 原型。奇怪的是,最初测试工作正常......但是在使用了几次之后。开始出现以下错误:
Tests in error: com.ndeveloper.spec.test.GreetingBeanTest: Cannot obtain MBeanServerConnect to: service:jmx:rmi:///jndi/rmi://127.0.0.1:1090/jmxrmi
错误测试:com.ndeveloper.spec.test.GreetingBeanTest:无法获得 MBeanServerConnect 到:service:jmx:rmi:///jndi/rmi://127.0.0.1:1090/jmxrmi
The surefire report says the following:
万无一失的报告说:
-------------------------------------------------------------------------------
Test set: com.ndeveloper.spec.test.GreetingBeanTest
-------------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 1.309 sec <<< FAILURE!
com.ndeveloper.spec.test.GreetingBeanTest Time elapsed: 0 sec <<< ERROR!
java.lang.IllegalStateException: Cannot obtain MBeanServerConnection to: service:jmx:rmi:///jndi/rmi://127.0.0.1:1090/jmxrmi
at org.jboss.as.arquillian.container.MBeanServerConnectionProvider.getConnection(MBeanServerConnectionProvider.java:64)
at org.jboss.as.arquillian.container.remote.RemoteDeployableContainer.getMBeanServerConnection(RemoteDeployableContainer.java:66)
at org.jboss.as.arquillian.container.remote.RemoteDeployableContainer.startInternal(RemoteDeployableContainer.java:52)
at org.jboss.as.arquillian.container.CommonDeployableContainer.start(CommonDeployableContainer.java:88)
at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController.perform(ContainerLifecycleController.java:144)
at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController.perform(ContainerLifecycleController.java:134)
at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController.forContainer(ContainerLifecycleController.java:182)
at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController.startContainer(ContainerLifecycleController.java:133)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)
at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
at org.jboss.arquillian.container.impl.client.ContainerDeploymentContextHandler.createContainerContext(ContainerDeploymentContextHandler.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:134)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:114)
at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:67)
at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController.perform(ContainerLifecycleController.java:83)
at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController.perform(ContainerLifecycleController.java:76)
at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController.forEachContainer(ContainerLifecycleController.java:175)
at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController.startContainers(ContainerLifecycleController.java:75)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)
at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:134)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:114)
at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:67)
at org.jboss.arquillian.container.test.impl.client.ContainerEventController.execute(ContainerEventController.java:83)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)
at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
at org.jboss.arquillian.test.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:54)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:134)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:114)
at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.beforeSuite(EventTestRunnerAdaptor.java:68)
at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:76)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:35)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:115)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:97)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.maven.surefire.booter.ProviderFactory$ClassLoaderProxy.invoke(ProviderFactory.java:103)
at $Proxy0.invoke(Unknown Source)
at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:150)
at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcess(SurefireStarter.java:91)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:69)
Caused by: java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is:
java.net.ConnectException: Connection refused: connect]
at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:338)
at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:248)
at org.jboss.as.arquillian.container.MBeanServerConnectionProvider.getConnection(MBeanServerConnectionProvider.java:60)
... 69 more
Caused by: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is:
java.net.ConnectException: Connection refused: connect]
at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:101)
at com.sun.jndi.toolkit.url.GenericURLContext.lookup(GenericURLContext.java:185)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at javax.management.remote.rmi.RMIConnector.findRMIServerJNDI(RMIConnector.java:1886)
at javax.management.remote.rmi.RMIConnector.findRMIServer(RMIConnector.java:1856)
at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:257)
... 71 more
Caused by: java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is:
java.net.ConnectException: Connection refused: connect
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:601)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:198)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:184)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:322)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:97)
... 76 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at java.net.Socket.<init>(Socket.java:375)
at java.net.Socket.<init>(Socket.java:189)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:22)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:128)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:595)
... 81 more
And finally my arquillian.xml is configured like this:
最后我的 arquillian.xml 配置如下:
<?xml version="1.0" encoding="UTF-8"?>
<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">
<!-- Uncomment to have test archives exported to the file system for inspection -->
<!-- <engine> -->
<!-- <property name="deploymentExportPath">target/</property> -->
<!-- </engine> -->
<!-- Example configuration for a remote JBoss AS 7 instance -->
<container qualifier="jboss" default="true">
<protocol type="jmx-as7">
<property name="executionType">REMOTE</property>
</protocol>
<configuration>
<property name="jbossHome">D:\JavaWindows\servers\jboss-as-web-7.0.1.Final\jboss-as-web-7.0.1.Final</property>
</configuration>
</container>
However I can't figure out why does arqullian stopped running the tests. As I told you before, they used to work however after a settings change?? Idk.... this error started to appear.
但是我不明白为什么 arqullian 停止运行测试。正如我之前告诉过你的,它们曾经在设置更改后工作?Idk .... 这个错误开始出现。
Just in case the test were run with the following command: mvn clean test -Parq-jbossas-remote
以防万一测试是使用以下命令运行的: mvn clean test -Parq-jbossas-remote
Thanks a lot.
非常感谢。
采纳答案by Marcos portela
The attribute jbossHome in the arquillian.xml should be as:
arquillian.xml 中的 jbossHome 属性应该是:
D:\JavaWindows\servers\jboss-as-web-7.0.1.Final\jboss-as-web-7.0.1.Final
D:\JavaWindows\servers\jboss-as-web-7.0.1.Final\jboss-as-web-7.0.1.Final
You should be add two slashes instead of one slash.
您应该添加两个斜杠而不是一个斜杠。
You shall verify if your jboss as 7 is running before the execution of tests. This is because you configured as REMOTE.
在执行测试之前,您应该验证您的 jboss as 7 是否正在运行。这是因为您配置为 REMOTE。
回答by Beijing Beijing
Depends on the type of container, i.e. JBoss 7 managed or remote, you need to have certain configurations set up correctly, in order to make Arquillian connect to the JBoss server.
取决于容器的类型,即 JBoss 7 托管或远程,您需要正确设置某些配置,以便让 Arquillian 连接到 JBoss 服务器。
In case of managed server you need to tell Arquillian where to find the JBoss. This could be done either by setting JBOSS_HOME as system properties, or add "jbossHome" configuration to arquillian.xml
如果是托管服务器,您需要告诉 Arquillian 在哪里可以找到 JBoss。这可以通过将 JBOSS_HOME 设置为系统属性来完成,或者将“jbossHome”配置添加到 arquillian.xml
In case of remote JBoss container, Arquillian needs 2 extra parameters: managementAddress managementPort,
对于远程 JBoss 容器,Arquillian 需要 2 个额外参数:managementAddress managementPort,
Arquillian use default 127.0.0.1:9999. If your server is running on different host/port, then the 2 parameters should be configured in arquillian.xml
Arquillian 使用默认值 127.0.0.1:9999。如果您的服务器在不同的主机/端口上运行,则应在 arquillian.xml 中配置这两个参数
Under following link you will find sevreal running examples for Arquillian Test with JBoss 7 or JBoss 5:
在以下链接下,您将找到使用 JBoss 7 或 JBoss 5 进行 Arquillian 测试的几个运行示例:
http://milestonenext.blogspot.de/2012/12/ejb3-integration-test-with-arquillian.html
http://milestonenext.blogspot.de/2012/12/ejb3-integration-test-with-arquillian.html