本系列教程共五篇,分别是:
一、 环境搭建、容器适配、单元测试
二、JBoss Forge、ShrinkWrap快速指南
三、使用 Arquillian 进行Java持久化测试
四、使用Arquillian + Drone + Selenium + Graphene 进行Web自动化测试
五、使用 Arquillian 在云端进行测试
其中,Web容器以JBoss-as-7.1.1为例,工程以maven目录结构为准。
本文所涉及到的内容有:
1. Arquillian
2. Maven
3. JUnit
4. Seam Framework
5. ShrinkWrap
6. JBoss Forge
forge
new-project --named arquillian-demo --topLevelPackage cn.demo
4.0.0
cn.demo
arquillian-demo
1.0.0-SNAPSHOT
JBOSS_NEXUS
http://repository.jboss.org/nexus/content/groups/public
arquillian-demo
maven-compiler-plugin
3.1
1.6
UTF-8
4.0.0
cn.demo
arquillian-demo
1.0.0-SNAPSHOT
JBOSS_NEXUS
http://repository.jboss.org/nexus/content/groups/public
arquillian-demo
maven-compiler-plugin
3.1
1.6
UTF-8
junit
junit
4.8.1
test
org.jboss.arquillian.junit
arquillian-junit-container
test
org.jboss.arquillian
arquillian-bom
1.1.3.Final
import
pom
package cn.demo;
public class Hello {
public String sayHello(String name) {
return "hello," + name;
}
}
package cn.demo;
import javax.inject.Inject;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(Arquillian.class)
public class HelloTest {
@Inject
private Hello helloBean; // 注入一个Hello对象
@Deployment
public static JavaArchive createDeployment() {
return ShrinkWrap.create(JavaArchive.class).addClass(Hello.class)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}
@Test
public void isHelloValid() {
Assert.assertNotNull(helloBean); // 判断注入是否成功
Assert.assertEquals("hello,Neo", helloBean.sayHello("Neo")); // 判断返回值是否正确
}
}
arq-jbossas-remote
org.jboss.spec
jboss-javaee-6.0
1.0.0.Final
pom
provided
org.jboss.as
jboss-as-arquillian-container-remote
7.1.1.Final
test
org.jboss.arquillian.protocol
arquillian-protocol-servlet
test
mvn test -Parq-jbossas-remote
mvn test -Parq-glassfish-remote
mvn clean install -Dmaven.test.skip=true
mvn test -Parq-jbossas-remote
arquillian-jbossas-managed
org.jboss.spec
jboss-javaee-6.0
1.0.0.Final
pom
provided
org.jboss.as
jboss-as-arquillian-container-managed
7.1.1.Final
test
org.jboss.arquillian.protocol
arquillian-protocol-servlet
test
你的JBoss安装目录
mvn test -Parquillian-jbossas-managed
mvn test -P你起的profile名
4.0.0cnftc1.0-SNAPSHOTpomrailway safety monitorrailway safety monitorhttp://dz.sdut.edu.cn/redmineftc-ejbftc-webftc-earftc-testsJBoss repositoryhttp://repository.jboss.org/nexus/content/groups/public/phantomjs
ftc
slow12.01.6.17.1.1.Final0.5.8.201207111220
1.6.2*firefoxproxyhttp://localhost:8080http://localhost:818014444localhost030000false${project.build.directory}/ftest-logs${project.build.directory}/ftest-output300truesrc/test/resources-ftestlocalhost/${project.build.finalName}/${env.JBOSS_HOME}/server/all${env.JBOSS_HOME}default${env.CATALINA_HOME}false
UTF-8
1.61.6
${maven.compiler.target}${maven.compiler.source}
postgresqlpostgresql9.1-901-1.jdbc44.111.1.2.Final
org.jboss.arquillianarquillian-bom1.1.2.Finalpomimportorg.jboss.arquillian.extensionarquillian-drone-bom1.2.3.Finalpomimportorg.jboss.arquillian.seleniumselenium-bom2.39.0pomimportcn.ftcftc-ejb${project.version}ejbcn.ftcftc-web${project.version}warcn.ftcftc-ear${project.version}org.jboss.seambom2.3.0.Finalpomimport
commons-loggingcommons-logging1.1.1providedcommons-collectionscommons-collections3.2provided
com.google.guavaguava${guava.version}org.slf4jslf4j-log4j12${slf4j.version}${jdbc.groupId}${jdbc.artifactId}${jdbc.version}testjavax.enterprisecdi-apiprovidedorg.jboss.spec.javax.annotationjboss-annotations-api_1.1_specprovidedjunitjunittestorg.jboss.arquillian.junitarquillian-junit-containertestorg.jboss.arquillian.graphenegraphene-webdriver2.0.1.Finalpomtestarquillian-demomaven-compiler-plugin3.11.61.6UTF-8maven-ear-plugin2.7org.codehaus.mojobuild-helper-maven-plugin1.7maven-resources-plugin2.5org.jboss.as.pluginsjboss-as-maven-plugin7.3.Finaldeploymaven-ejb-plugin2.33.0maven-war-plugin2.1.1truefalse${project.build.finalName}firefoxfirefoxchromechromearq-jboss-as-remoteorg.jboss.asjboss-as-arquillian-container-remote7.1.1.Finaltestorg.jboss.arquillian.protocolarquillian-protocol-servlettestarq-jboss_as_managed_7.xmaven-surefire-plugin2.14.1JBOSS_AS_MANAGED_7.Xorg.jboss.asjboss-as-arquillian-container-managed7.1.1.Final
4.0.0ftccn1.0-SNAPSHOTcn.ftcftc-testsftc Integration Tests Module (EE6)cn.ftcftc-ejbejbtest
org.slf4jslf4j-log4j12testorg.hibernate.javax.persistencehibernate-jpa-2.0-apiorg.jboss.spec.javax.facesjboss-jsf-api_2.1_spec
src/test/resources