Java Reference
In-Depth Information
Writing your first Arquillian test
Once the configuration is complete, we will finally code our test. So, create a Java class
named TicketTest under the package
com.packtpub.wflydevelopment.chapter13.test . The first thing that you
will add to this class is the following annotation that tells JUnit to use Arquillian as the test
controller:
@RunWith(Arquillian.class)
public class TicketServiceTest {
}
Arquillian then looks for a static method with the @Deployment annotation; it creates a
micro deployment including all the specified classes and resources (instead of deploying
the whole application), allowing to test only part of the system:
@Deployment
public static Archive<?> createTestArchive() {
return ShrinkWrap.create(WebArchive.class)
addPackage(SeatType.class.getPackage())
.addPackage(TicketService.class.getPackage())
.addPackage(LoggerProducer.class.getPackage())
.addAsResource("META-INF/persistence.xml")
.addAsWebInfResource(EmptyAsset.INSTANCE,
"beans.xml");
}
The fluent API provided by the ShrinkWrap project ( http://www.jboss.org/shrinkwrap )
makes this technique possible using the create method, which accepts the type of de-
ployment unit ( WebArchive ) as the argument and all the resources are included in this
archive. In our case, instead of including all the single classes, we use the addPackage
utility method that adds all the classes that are contained in a class package (for example,
by adding the SeatType.class.getPackage() method, we will include all the
classes that are in the same package as the SeatType class). Our project uses the JPA, so
we also add persistence configuration; here, we specify a path to the .xml file, so we can
point, for example, to some other test configuration using some other non-production data-
Search WWH ::




Custom Search