Best current framework for unit testing EJB3 / JPA

Dark Castle picture Dark Castle · Mar 21, 2010 · Viewed 28.5k times · Source

Starting a new project using EJB 3 / JPA, mainly stateless session beans and batch jobs. I've used JUnit in the past on standard Java webapps and it seemed to work pretty well. In EJB2 unit testing was a pain and required a running container such as JBoss to make the calls into. Now that we're going to be working in EJB3 / JPA I'd like to know what companies are using to write and run these tests. Are Junit and JMock still considered relevant or are there other newer frameworks that have come around that we should investigate?

Answer

ewernli picture ewernli · Mar 23, 2010

IMHO, yes they are still relevant.

With EJB3, you can test you EJB either like regular POJO, or as managed bean using an embedded EJB container.

Same for JPA, you can either embed a JPA implementation for your test and use an in-memory database, or you can mock the data layer completely.

For my last EJB project I had written a bit of glue code to test the EJB because embedded EJB container were not mature enough, but now I would go for an embedded EJB container + JUnit.

A few resources

But there are many others easily findable