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开发者_C百科've not used mocking framework before and particularly interested in low learning curve / great getting started guide.
I should clarify, using EJB 2.
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.
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.
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.
精彩评论