4.4. Changes in the testing framework
Seam does not support SeamTest and JBoss Embedded legacy components (as supported in Seam 2.2).
Arquillian is the replacement for JBoss Embedded. Extend
org.jboss.seam.mock.JUnitSeamTest instead of org.jboss.seam.mock.SeamTest. DBUnit testing is provided by org.jboss.seam.mock.DBJUnitSeamTest instead of org.jboss.seam.mock.DBUnitSeamTest. Assertion issues mean JUnit is the preferred testing framework over TestNG. Complete the migration to Junit and Arquillian as follows:
- Add the following annotation to your test class:
@RunWith(Arquillian.class)
- In your test class, extend
org.jboss.seam.mock.JUnitSeamTestinstead oforg.jboss.seam.mock.SeamTest. - Add a method for creating ShrinkWrap deployment; Seam examples and integration testsuite uses helper class for this purpose. For example, see the Booking sample test modules
jboss-seam-x.y.z.Final/examples/booking/booking-ejb/src/test/java/org/jboss/seam/example/booking/test/Deployments.java. package org.jboss.seam.example.booking.test; import java.io.File; import org.jboss.seam.example.booking.Booking; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.jboss.shrinkwrap.resolver.api.maven.Maven; public class Deployments { public static WebArchive bookingDeployment() { File[] libs = Maven.resolver().loadPomFromFile("pom.xml") .importCompileAndRuntimeDependencies() .resolve("org.jboss.seam:jboss-seam") .withTransitivity().asFile(); return ShrinkWrap.create(WebArchive.class, "seam-booking.war") .addPackage(Booking.class.getPackage()) .addAsWebInfResource("META-INF/ejb-jar.xml", "ejb-jar.xml") .addAsResource("import.sql") .addAsResource("persistence.xml", "META-INF/persistence.xml") .addAsWebInfResource("components.xml") .addAsWebInfResource("jboss-deployment-structure.xml") .addAsResource("seam.properties") .addAsWebInfResource("web.xml") .addAsLibraries(libs); } }
- Add a method for creating test deployment archive as:
@Deployment(name="_your_test_name_") @OverProtocol("Servlet 3.0") public static org.jboss.shrinkwrap.api.Archive<?> createDeployment(){}
The following example is taken from the Booking example test suite: @Deployment(name="BookingTest") @OverProtocol("Servlet 3.0") public static Archive<?> createDeployment() { return Deployments.bookingDeployment(); }
In the Booking example, call the already created bookingDeployment() method from the Deployment class. - Add the
arquillian.xmlfile in the root of your classpath to run Arquillian tests. The file content should specify the path to a remote or managed container and some specific options for JVM or Arquillian. An example of an arquillian file is available atjboss-seam-x.y.z.Final/examples/booking/booking-ejb/src/test/resources/arquillian.xml. <?xml version="1.0" encoding="UTF-8"?> <arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://jboss.org/schema/arquillian" xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd"> <engine> <property name="deploymentExportPath">target/</property> </engine> <container qualifier="jboss" default="true"> <configuration> <property name="javaVmArguments">-Xmx1024m -XX:MaxPermSize=1024m ${jacoco.agent}</property> <property name="serverConfig">standalone.xml</property> </configuration> </container> </arquillian>