scottyab
scottyab

Reputation: 24039

Best Mock object framework for EJB junit tests

Which mocking framework is preferred for testing EJB's (specifically Message Driven Beans), I'm looking at MockObjects, easyMock, MockEJB and mockito but open all.

I've not used mocking framework before and particularly interested in low learning curve / great getting started guide.

I should clarify, using EJB 2.

Upvotes: 2

Views: 6326

Answers (3)

Arjan Tijms
Arjan Tijms

Reputation: 38163

A framework specifically build for this is Arquillian - http://www.jboss.org/arquillian.

This lets you test in-container via JUnit. You can test individual beans or larger collections. You can provide mocks by simply packaging other implementations in the test archive.

When using Java EE 6 (JBoss AS 6, Glassfish V3), you can run the container in embedded mode which simplifies matters and saves you in run-time overhead.

EJB2 is notoriously difficult to test though. If possible I suggest you drop it completely in favor of EJB3.x, but of course this might not be an option for you.

Upvotes: 4

Tom Anderson
Tom Anderson

Reputation: 47233

It's not a mocking framework, but you might like to have a look at OpenEJB, which is a lightweight EJB container suitable for, amongst other things, use in unit tests. It will save you having to mock the container's interfaces, and you can still mock interfaces to other components.

Upvotes: 2

skaffman
skaffman

Reputation: 403581

If you're using EJB 3.x, then is heavily interface-based, and so your usual run-of-the-mill mocking frameworks will do just fine for unit tests; the fact that the code is used by the EJB framework isn't really relevant.

EJB 2.x is a different (and ugly) kettle of fish, though, since it doesn't conform to any of the usual sane rules of software design. Your best bet there is probably a framework like Cactus.

Upvotes: 2

Related Questions