Book Image

Arquillian Testing Guide

By : John D. Ament
Book Image

Arquillian Testing Guide

By: John D. Ament

Overview of this book

<p>Integration testing sometimes involves writing complex codes. This book introduces you to the capabilities of Arquillian to enable you to write simple code with a broad range of integration tests for java applications. <br /><br />Arquillian Testing Guide serves as an introductory book to writing simple codes for testing java applications. This book will help you to develop richer test cases which can be run automatically while performing rigorous testing of the software. <br /><br />Arquillian Testing Guide introduces you to Arquillians features and capabilities. This book will help you understand the mechanism of creating deployments and test against those deployments. The book begins with basic JUnit test cases beginning with an enterprise test case, which then go on to discuss remote testing. During the course of the book, you will also learn how to mix container and non-container tests into a single test case. By the end of the book, you will have learned how to extend JUnit tests to work with Arquillian and deploy them to a container automatically.</p>
Table of Contents (17 chapters)

Testing against a database using JPA


It's fairly simple to test JPA logic. You will need to ensure that you are deploying to a nearly complete container. You won't need to deploy JPA applications to a CDI embedded container; you need the resources of your application server – managed database connection's transaction support.

Assuming that you have an EJB that exposes your DAO, it's fairly simple to create test data and load it to your database. In simple terms, one way you can do this is to create the test data in the first step of a test and then use that data in the subsequent tests, finally deleting it when the test is over. One thing to keep in mind is that you should make sure you always work off a clean database and that you create and drop your test database with each test. Let's consider a simple persistence.xml file:

<persistence xmlns="http://java.sun.com/xml/ns/persistence" 
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
             xsi:schemaLocation=...