O'Reilly logo

Arquillian Testing Guide by John D. Ament

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required