在观看JBoss的Arquillian上的一些视频教程时,我偶然发现了他们的另一个名为ShrinkWrap的项目(因为Arquillian使用它).
在他们的项目页面上花了一些时间之后,我似乎无法找到几个问题的具体答案,而且它似乎是一个非常新的(不成熟的)项目,它背后没有一个大的开发社区.特别:
提前致谢!
我正在使用Arquillian为我的测试注入依赖项.如果我将bean直接注入我的测试类,它可以正常工作,但是如果bean必须注入它们自己的依赖项,那么这些依赖项就不会被注入.
例如:FacLptConfiguration bean正确导入我的Test Class,但它没有被注入CfdFileCreator bean.我将FacLptConfigurtion注入测试类只是为了确认注入是否有效,但是这个类的用户是CfdFileCreator.
@RunWith(Arquillian.class)
public class CfdFileCreatorArquillianTest {
@Deployment
public static WebArchive createDepolyment() {
return ShrinkWrap.create(WebArchive.class)
.addClass(FacLptConfiguration.class)
.addClass(InterimFileCreator.class)
.addClass(CfdFileCreator.class)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
.addAsWebInfResource(new File("C:/aLearn/FacLpt/web/WEB-INF/env-entries.properties"));
}
public static String TEST_FOLDER = "C:/aLearn/FacLpt/src/test/testdata/pruebas/";
@Inject
private FacLptConfiguration facLptConfiguration;
@Inject
private CfdFileCreator cfdFileCreator;
@Test
public void createCfd() {
System.out.println("in createCFD");
cfdFileCreator.createCFDFile();
}
Run Code Online (Sandbox Code Playgroud)
}
这些注射不起作用:
@Singleton
public class CfdFileCreator {
@Inject
private InterimFileCreator interimFileCreator;
@Inject
private FacLptConfiguration facLptConfiguration;
Run Code Online (Sandbox Code Playgroud) 我试图使用的Arquillian无人机驾驶员我的测试,但是,出于某种原因注释@Before
,@After
,@BeforeClass
并且@AfterClass
被完全忽略.
我是Java/jUnit/Arquillian环境的新手(一直使用Python),所以我可能会在这里犯一些愚蠢的错误.
import org.jboss.arquillian.drone.api.annotation.Drone;
import org.jboss.arquillian.junit.Arquillian;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import com.eyereturn.warlock.client.pages.login.LoginPage;
@RunWith(Arquillian.class)
public class TestDroneLogin {
@Drone
private WebDriver driver;
@Before
public void setup(){
driver.navigate().to("http://google.com");
}
@Test
public void testInput(){
driver.findElement(By.cssSelector("input#gbqfq"));
}
}
Run Code Online (Sandbox Code Playgroud)
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">
<extension qualifier="webdriver">
<property name="browserCapabilities">chrome</property>
</extension>
</arquillian>
Run Code Online (Sandbox Code Playgroud)
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>
<groupId>com.myproj</groupId>
<artifactId>proj-integration-tests</artifactId>
<version>1.0.0-SNAPSHOT</version> …
Run Code Online (Sandbox Code Playgroud) 我正在尝试从本教程中运行一个简单的CDI测试.下面是我的JUNIT和POM.不确定错误是什么.感谢任何帮助.
错误
java.lang.NullPointerException
at com.aravind.jee6.cdi.basic.GreeterTest.greet(GreeterTest.java:32)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.jboss.arquillian.junit.Arquillian$6$1.invoke(Arquillian.java:270)
at org.jboss.arquillian.container.test.impl.execution.LocalTestExecuter.execute(LocalTestExecuter.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
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:135)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:115)
at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:67)
at org.jboss.arquillian.container.test.impl.client.protocol.local.LocalContainerMethodExecutor.invoke(LocalContainerMethodExecutor.java:50)
at org.jboss.arquillian.container.test.impl.execution.RemoteTestExecuter.execute(RemoteTestExecuter.java:120)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
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:135)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:115)
at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:67)
at org.jboss.arquillian.container.test.impl.execution.ClientTestExecuter.execute(ClientTestExecuter.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at …
Run Code Online (Sandbox Code Playgroud) 信息:我的应用程序是一个简单的 JAX-RS 服务,它将一些值存储在 JBoss 7.1 提供的缓存中。
我想使用 Arquillian 调用服务并测试响应。但不幸的是,当我尝试运行测试时出现此错误:
java.lang.IllegalArgumentException:
Can not set org.infinispan.manager.CacheContainer field
com.company.DataCache.container to
org.jboss.as.clustering.infinispan.DefaultEmbeddedCacheManager
Run Code Online (Sandbox Code Playgroud)
这是我的 DataCache 类:
@ManagedBean
public class DataCache<K, V> {
@Resource(lookup="java:jboss/infinispan/container/hibernate")
private CacheContainer container;
private Cache<K, V> cache;
@PostConstruct
public void start() {
this.cache = this.container.getCache();
}
public Cache<K, V> getCache() {
return cache;
}
}
Run Code Online (Sandbox Code Playgroud)
我的测试类看起来像这样:
@RunWith(Arquillian.class)
@RunAsClient
public class SyncClientServerTest extends RbmlClientServerTest {
@Deployment(testable = false)
public static WebArchive createDeployment() {
MavenDependencyResolver mvnResolver = DependencyResolvers.use(MavenDependencyResolver.class).loadMetadataFromPom("pom.xml").goOffline();
return ShrinkWrap
.create(WebArchive.class, "cache-service.war")
.addPackages(true, …
Run Code Online (Sandbox Code Playgroud) dependency-injection exception infinispan jboss-arquillian jboss7.x
我能够调试jboss-eap 6.2,但我必须启动和停止服务器.在eclipse下使用Kepler SR2(使用JBosstools)当我在调试模式下启动时,Junit测试会冻结显示控制台:
mars 14, 2014 8:45:15 AM org.jboss.as.arquillian.container.managed.ManagedDeployableContainer startInternal
INFO: Starting container with: ["C:\Program Files\Java\jdk1.7.0_25\bin\java", -Xdebug, -agentlib:jdwp=transport=dt_socket,address=8787,server=y,suspend=y, -ea, -Djboss.home.dir=C:\_server\jboss-eap-6.2, -Dorg.jboss.boot.log.file=C:\_server\jboss-eap-6.2\standalone\log\boot.log, -Dlogging.configuration=file:/C:/_server/jboss-eap-6.2/standalone/configuration/logging.properties, -Djboss.bundles.dir=C:\_server\jboss-eap-6.2\bundles, -jar, C:\_server\jboss-eap-6.2\jboss-modules.jar, -mp, C:\_server\jboss-eap-6.2\modules, -jaxpmodule, javax.xml.jaxp-provider, org.jboss.as.standalone, -server-config, standalone.xml]
Listening for transport dt_socket at address: 8787
Run Code Online (Sandbox Code Playgroud)
然后,如果我在eclispe下启动JBOss-eap,则测试在启用断点的情况下运行正常.最后服务器没有停止,我必须手动停止它
我做错了什么?
这是我的Aquillian conf(在windows7上工作):
<container qualifier="jboss" default="true">
<configuration>
<property name="jbossHome">C:\_server\jboss-eap-6.2</property>
<property name="javaVmArguments">-Xdebug -agentlib:jdwp=transport=dt_socket,address=8787,server=y,suspend=y</property>
<property name="javaHome">C:\Program Files\Java\jdk1.7.0_25</property>
</configuration>
</container>
Run Code Online (Sandbox Code Playgroud)
这是pom.xml和paretn pom之后
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>ee6-parent-root</artifactId>
<groupId>sopra.academy.jee6</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>ee6-parent-ejb-junit</artifactId>
<packaging>pom</packaging>
<repositories>
<repository>
<id>thirdparty-releases</id>
<name>JBoss Thirdparty Releases</name>
<url>https://repository.jboss.org/nexus/content/repositories/thirdparty-releases</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.jboss.spec.javax.ejb</groupId> …
Run Code Online (Sandbox Code Playgroud) 基于原型我创建了一个java ee应用程序.有一个包括arquillian测试运行正常.它只是在@Stateless bean上调用一个持久化实体的方法.
现在我添加了一些实体与一些关系,我为他们写了一个测试.但在坚持任何实体我得到
Transaction is required to perform this operation (either use a transaction or extended persistence context)
Run Code Online (Sandbox Code Playgroud)
我想我需要用@Transactional标记testmethod,但似乎不是在类路径中.在注入的EntityManager上手动调用事务会产生另一个错误.那么如何正确设置这样的测试和依赖.
编辑 Grzesiek D.建议这里有一些细节.这是实体(与其他人联系):
@Entity
public class Booking implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* internal id.
*/
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", updatable = false, nullable = false)
private Long id;
/**
* Used for optimistic locking.
*/
@Version
@Column(name = "version")
private int version;
/**
* A …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用wildfly配置arquillian但是在运行测试的过程中出现以下错误:
java.lang.RuntimeException: Could not create new instance of class org.jboss.arquillian.test.impl.EventTestRunnerAdaptor
at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:165).......
Caused by: java.lang.reflect.InvocationTargetException: null
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
...........
Caused by: java.lang.RuntimeException: Could not create new instance of class org.jboss.arquillian.core.impl.ManagerImpl
at org.jboss.arquillian.core.spi.SecurityActions.newInstance(SecurityActions.java:165)
at .................
Caused by: java.lang.reflect.InvocationTargetException: null
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at ...............
Caused by: java.lang.RuntimeException: Could not create and process manager
at org.jboss.arquillian.core.impl.ManagerImpl.<init>(ManagerImpl.java:105)......
Caused by: java.lang.IllegalArgumentException: Attempted to register the same Observer: org.jboss.as.arquillian.container.ServerSetupObserver multiple times, please check classpath for conflicting jar versions …
Run Code Online (Sandbox Code Playgroud) 我的项目配置是带有Gradle和Wildfly 10 CR4的Arquillian.我已经将wildfly中的standalone.conf更改为默认使用standalone-full.xml.不幸的是,Arquillian似乎使用standalone.xml启动了嵌入式wildfly.我想我需要为嵌入式服务器更改一个不同的文件,因为它不是'独立'但我找不到它.
我有一个带有一些Arquillian测试的maven项目(包括无人机/石墨烯测试).
当我使用maven构建我的项目时,所有使用Graphene和Drone或Warp的Arquillian测试将失败并出现以下异常
Running de.mmo.arq.model.diverses.stammdaten.geldinstitut.GeldinstitutBlzTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 4.862 sec <<< FAILURE! - in de.mmo.arq.model.diverses.stammdaten.geldinstitut.GeldinstitutBlzTest
de.mmo.arq.model.diverses.stammdaten.geldinstitut.GeldinstitutBlzTest Time elapsed: 4.862 sec <<< ERROR!
org.jboss.shrinkwrap.api.exporter.ArchiveExportException: Failed to write asset to output: /WEB-INF/classes/de/mmo/base/dao/CrudService.class
Caused by: java.lang.IncompatibleClassChangeError: class org.jacoco.core.internal.flow.ClassProbesVisitor has interface org.objectweb.asm.ClassVisitor as super class
Run Code Online (Sandbox Code Playgroud)
这是魔法应该发生的地方
<build>
<finalName>browser</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<tagBase>...</tagBase>
<useReleaseProfile>false</useReleaseProfile>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>jacoco</id>
<dependencies>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.core</artifactId>
<scope>test</scope> …
Run Code Online (Sandbox Code Playgroud) java maven jboss-arquillian arquillian-drone jacoco-maven-plugin
我收到异常
FAILED CONFIGURATION: @BeforeSuite arquillianBeforeSuite
java.lang.NoSuchMethodError: org.jboss.remoting3.Endpoint.builder()Lorg/jboss/remoting3/EndpointBuilder;
at org.jboss.as.controller.client.impl.RemotingModelControllerClient.getOrCreateChannel(RemotingModelControllerClient.java:117)
at org.jboss.as.controller.client.impl.RemotingModelControllerClient$1.getChannel(RemotingModelControllerClient.java:59)
at org.jboss.as.protocol.mgmt.ManagementChannelHandler.executeRequest(ManagementChannelHandler.java:147)
at org.jboss.as.protocol.mgmt.ManagementChannelHandler.executeRequest(ManagementChannelHandler.java:122)
Run Code Online (Sandbox Code Playgroud)
使用 TestNG 和 wildfly11 在 Eclipse Oxygen 中运行 Arquillian 测试。我的Maven配置如下:
<dependency>
<groupId>org.jboss.arquillian.testng</groupId>
<artifactId>arquillian-testng-container</artifactId>
<version>1.1.13.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.11</version>
</dependency>
<dependency>
<groupId>org.wildfly.arquillian</groupId>
<artifactId>wildfly-arquillian-container-managed</artifactId>
<version>2.0.1.Final</version>
<scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud) 我们有一个包含多个子模块的EAR项目(多个EJB,Web项目,应用程序客户端等).单一测试的自然范围是它们各自的子模块(因为它们应该是测试隔离单元).
在很短的时间内,我们引入了非明显的测试依赖项.项目正在嘲笑来自其他项目的功能等.很快我们的架构演变成了几个带有模拟的独立jar文件(web项目1个模拟,ejb 2模拟等); 我们将这些模拟与EAR连接起来并消耗子模块中的模拟("瘦战"风格).
EAR
Modules
WEB 1
WEB 2
EJB 2
EJB 3
etc
Libs
Shared library 1
Shared Library 2
Testing dependencies
WEB 1 mocks
WEB 2 mocks
EJB 1 mocks
EJB 2 mocks
etc
WEB1
Uses EJB 1 and EJB 3
Uses Shared Library 1
Testing
Consumes EJB 1 and EJB 2 mocks
Run Code Online (Sandbox Code Playgroud)
无论如何,我们团队的共识是模拟失控.我们希望向Arquillian发展并在容器内部进行测试(例如,向集成测试).我们还介绍了ATTD(最初只是使用Drone进行功能测试,但我希望尽快安装功能齐全的Thucydidies + JBehave或EasyB).
测试可能取决于来自多个子模块的资源.ShrinkWrap可以保证事情不会失控.
所以我的问题是:我应该在哪里放置测试,故事,Arquillian配置文件等等?
我觉得EAR是分组一切的最佳场所:
EAR
Modules
Test
src
Java
Test 1
Test 2
Resources
Configuration Files
Stories
Story 1
Story 2 …
Run Code Online (Sandbox Code Playgroud) jboss-arquillian ×12
java ×6
cdi ×2
maven ×2
wildfly ×2
eclipse ×1
ejb ×1
exception ×1
gradle ×1
infinispan ×1
jboss ×1
jboss-weld ×1
jboss7.x ×1
jpa ×1
junit ×1
module ×1
shrinkwrap ×1
webdriver ×1
weld ×1
wildfly-8 ×1