如何将POM中的所有依赖项添加到arquillian?
Maven.resolver().loadPomFromFile("pom.xml").importRuntimeDependencies()
.as(File.class);
Run Code Online (Sandbox Code Playgroud)
我找到了那条线,但我Maven
在intellij中是红色的,因为它找不到这个类.我不知道我需要哪些依赖项.还是有更好的方法?
为什么Maven默认会跳过我的所有测试呢?我的pom.xml
配置文件很少,而且我无法通过它们运行我的测试.我的一个档案看起来像
<profile>
<id>jsf-test</id>
<dependencies>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-arquillian-container-remote</artifactId>
<version>${jboss.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jsf.tests</groupId>
<artifactId>jsf-app</artifactId>
<version>${jsf-app.version}</version>
<type>war</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-jsf-app</id>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.jsf.tests</groupId>
<artifactId>jsf-app</artifactId>
<version>${jsf-app.version}</version>
<type>war</type>
<destFileName>jsfapp.war</destFileName>
<outputDirectory>target</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire.version}</version>
<configuration>
<skipTests>false</skipTests> <!-- desperate trial -->
<properties>
<property>
<name>listener</name>
<value>${testng.listeners}</value>
</property>
</properties>
</configuration>
</plugin>
</plugins>
</build>
</profile>
Run Code Online (Sandbox Code Playgroud)
如果我运行mvn verify -Pjsf-test
然后编译项目,则将jsf-app
工件正确复制到目标目录中并跳过测试.mvn verify -Dtest=TestCalculator
有相同的结果.我正在使用Arquillian
并TestNG …
我们使用arquillian-junit-container 1.0.0最终版本进行Junit测试.
我们拥有如此多的测试类和每个测试类作为@Deployment方法,因此当我一起运行所有测试时,它会产生内存和性能问题.
任何人都可以通过告诉我们如何避免每个单独的类的多个部署来帮助我解决这个问题.我们如何在Arquillian中为所有测试用例实现单一部署?
我正在使用arquillian为Tomcat 8上部署的JAX-RS/Jersey Webservice创建集成测试.
我正在尝试这样的POST请求:
E dummy = dummyFactory.manufacturePojo(getSubClassType());
dummy.setId(null);
Client client = ClientBuilder.newClient();
WebTarget target = client.target(BASE_URI).path("bandeira");
Response response = target.request(MediaType.APPLICATION_JSON)
.header(HttpHeaders.AUTHORIZATION, CHAVE_TESTE)
.header(HttpHeaders.CONTENT_TYPE, "application/json")
.post(Entity.entity(dummy, MediaType.APPLICATION_JSON));
Run Code Online (Sandbox Code Playgroud)
当我这样做时,我得到这个例外:
Caused by: java.lang.IllegalStateException: Already connected
at sun.net.www.protocol.http.HttpURLConnection.setRequestProperty(HttpURLConnection.java:3000)
at org.glassfish.jersey.client.HttpUrlConnector.setOutboundHeaders(HttpUrlConnector.java:364)
at org.glassfish.jersey.client.HttpUrlConnector.access$100(HttpUrlConnector.java:91)
at org.glassfish.jersey.client.HttpUrlConnector$4.getOutputStream(HttpUrlConnector.java:327)
at org.glassfish.jersey.message.internal.CommittingOutputStream.commitStream(CommittingOutputStream.java:201)
at org.glassfish.jersey.message.internal.CommittingOutputStream.commitStream(CommittingOutputStream.java:195)
at org.glassfish.jersey.message.internal.CommittingOutputStream.commit(CommittingOutputStream.java:263)
at org.glassfish.jersey.message.internal.OutboundMessageContext.commitStream(OutboundMessageContext.java:816)
at org.glassfish.jersey.client.ClientRequest.writeEntity(ClientRequest.java:546)
at org.glassfish.jersey.client.HttpUrlConnector._apply(HttpUrlConnector.java:331)
at org.glassfish.jersey.client.HttpUrlConnector.apply(HttpUrlConnector.java:243)
at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:246)
... 149 more
Run Code Online (Sandbox Code Playgroud)
我可以使用一些启发式,因为我还在学习arquillian和Jersey客户端API :)谢谢
我想知道是否有一种简单的方法来确定Java类以递归方式扩展或实现的完整类型列表?
例如:
class Foo extends Bar implements I1, I2 {...}
class Bar implements I3 {...}
interface I1 extends I4, I5 {...}
interface I2 {...}
interface I3 {...}
interface I4 {...}
interface I5 {...}
class ClassUtil {
public static Set<Class<?>> getAllExtendedOrImplementedTypesRecursively(Class<?> clazz){
???
}
}
import static org.junit.Assert.*;
public class ClassUtilTest {
@Test
public void shouldEqualClasses(){
Set<Class<?>> types = ClassUtil.getAllExtendedOrImplementedTypesRecursively(Foo.class);
Set<Class<?>> checklist = new HashSet<>();
checklist.add(Foo.class);
checklist.add(Bar.class);
checklist.add(I1.class);
checklist.add(I2.class);
checklist.add(I3.class);
checklist.add(I4.class);
checklist.add(I5.class);
assertTrue(checklist.containsAll(types));
assertTrue(types.containsAll(checklist));
}
}
Run Code Online (Sandbox Code Playgroud)
想想Arquillian ShrinkWrap创作助手.
更新:由于Class对象没有实现Comparable>我还需要找到一种创建Set(或类似类)的方法,而不需要实现Comparable接口(例如,仅依赖于类对象的hashcode).
更新: …
java.lang.IllegalStateException: Could not find backup for factory javax.faces.context.FacesContextFactory.
is caused by the presence of a JSF API inside a dependency. I'm eager to provide dependencies in the WAR or EAR of my Java EE applications instead of using the dependency artifacts provided by the server because that increases flexibility when it comes to necessary updates (assuming that updating the server artifacts) in my experience. That makes it easy to compare a deployment on Payara 4.1.2.181 to one to the …
是否有可能使用Arquillian的某种模拟框架,或者精确地如何模拟注入的EJB?我知道,通过使用CDI(上下文和依赖注入),可以在测试中注入替代方案.但是如果没有CDI作为注入机制,当我只使用EJB注入时,这怎么可能呢?
最近我用服务接口模拟实现测试了我的EJB如下:
// Service inteface
public interface Audit {
void audit(String info);
}
// Mock implementation
@Stateless
public class MockAuditBean implements Audit {
public static String lastInfo = null;
@Override
public void audit(String info) {
this.lastInfo = info;
}
}
// assert in test
assertTrue(MockAuditBean.lastInfo.contains("dummy"));
Run Code Online (Sandbox Code Playgroud)
这种方法是可行的,但需要大量的自定义模拟实现.更糟糕的是,注入的模拟实例是代理并使用服务接口.这些不能转换为模拟实现类来比较结果.只能使用静态成员和模拟实现方法.
我还测试了另一种手动设置相关EJB的可能性.这种方法有几个缺点.它要求测试的目标EJB具有非私有成员或设置者.当目标EJB依赖于@PostConstruct生命周期注释时,您必须在手动"注入"设置后调用它.此解决方案的优点是能够使用模拟框架,如mockito或jMock.
是否有人分享经验,如何测试和设置此类集成测试,甚至使用模拟框架?
我一直试图运行这个Arquillian的例子
https://github.com/arquillian/arquillian-examples/tree/master/arquillian-tutorial
在Eclipse中导入时没有错误
但是,当我作为JUnit Test运行时,我收到此错误:
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:160)
at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:111)
at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:97)
at org.jboss.arquillian.test.spi.TestRunnerAdaptorBuilder.build(TestRunnerAdaptorBuilder.java:52)
at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:93)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:156)
... 10 more
Caused by: org.jboss.arquillian.container.impl.ContainerCreationException: Could not create Container jbossas-managed
at org.jboss.arquillian.container.impl.LocalContainerRegistry.create(LocalContainerRegistry.java:85)
at org.jboss.arquillian.container.impl.client.container.ContainerRegistryCreator.createRegistry(ContainerRegistryCreator.java:76)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at …
Run Code Online (Sandbox Code Playgroud) 到目前为止,我已经使用Arquillian和嵌入式Glassfish 4.x运行了集成测试.当我遇到错误ARQ-1458时,我尝试迁移到Wildfly 8.0.0.Beta1.
我在Maven的代表是:
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.1.2.Final</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-arquillian-container-embedded</artifactId>
<version>8.0.0.Beta1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-embedded</artifactId>
<version>8.0.0.Beta1</version>
<scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
运行我的测试时,我得到jbossHome为null的错误.我没有arquillian.xml.当检查Github源的wildfly-arquillian-container-embedded(POM)时,我想知道为什么嵌入式容器需要JBOSS_HOME?我理解将它用于托管和远程变体,但为什么我需要它用于嵌入式变体?Arquillian页面也只有JBoss AS作为托管服务器的例子,所以我不知道它有可能(但为什么还有wildfly-arquillian-container-embedded?)?
或者我应该坚持使用maven-dependency-plugin来下载容器的托管容器(请参阅http://arquillian.org/guides/getting_started/#add_more_containers - bottom)?
谢谢和最好的问候!
确切的错误是:
org.jboss.arquillian.container.spi.ConfigurationException: jbossHome 'null' must exist
at org.jboss.arquillian.container.spi.client.deployment.Validate.configurationDirectoryExists(Validate.java:139)
at org.jboss.as.arquillian.container.embedded.EmbeddedContainerConfiguration.validate(EmbeddedContainerConfiguration.java:102)
at org.jboss.arquillian.container.impl.ContainerImpl.createDeployableConfiguration(ContainerImpl.java:115)
at org.jboss.arquillian.container.impl.ContainerImpl.setup(ContainerImpl.java:181)
at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController$7.perform(ContainerLifecycleController.java:149)
at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController$7.perform(ContainerLifecycleController.java:145)
at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController.forContainer(ContainerLifecycleController.java:255)
at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController.setupContainer(ContainerLifecycleController.java:144)
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:606)
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.container.impl.client.ContainerDeploymentContextHandler.createContainerContext(ContainerDeploymentContextHandler.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at …
Run Code Online (Sandbox Code Playgroud)