Unit Testing an EJB

ejb, jakarta-ee, java, junit, tdd

Solution

I'm assuming you are talking about EJB2.x Session Beans. For these kind of animals, what I like to do is:

- Use the Session Bean as a wrapper that just delegates logic to a POJO that you can test easily outside a container. Outside container testing is better, faster, easier, etc but won't cover things such as deployment descriptor validation - and/or -

- Use something like Cactus for in-container testing (check the Howto EJB documentation) - and/or -

- Build and deploy your EJB module with Cargo for integration testing.

Problem

I'm looking for a way to apply TDD to Session Beans. can anyone provide advices and links on how to unit test them ? how to use JUnit to do so ? P.S : I'm new to Test Driven Development and Session Beans. I'm using EJB v2.

Original source