EJB junit 测试的最佳模拟对象框架
哪种模拟框架更适合测试 EJB(特别是消息驱动 Bean),我正在查看 MockObjects,easyMock、MockEJB 和mockito 但全部打开。
我以前没有使用过模拟框架,并且对低学习曲线/出色的入门指南特别感兴趣。
我应该使用 EJB 2 来澄清。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
专门为此构建的框架是
Arquillian
- http://www.jboss.org/arquillian 。这使您可以通过 JUnit 进行容器内测试。您可以测试单个 bean 或更大的集合。您可以通过简单地将其他实现打包到测试存档中来提供模拟。
使用 Java EE 6(JBoss AS 6、Glassfish V3)时,您可以在嵌入式模式下运行容器,这简化了问题并节省了运行时开销。
然而 EJB2 是出了名的难以测试。如果可能的话,我建议您完全放弃它,转而使用 EJB3.x,但这当然可能不是您的选择。
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.
它不是一个模拟框架,但您可能想看看 OpenEJB,它是一个轻量级 EJB 容器,适合除其他外,用于单元测试。它将使您不必模拟容器的接口,并且您仍然可以模拟其他组件的接口。
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.
如果您使用的是 EJB 3.x,那么它很大程度上是基于接口的,因此您通常使用的普通模拟框架对于单元测试来说就足够了;该代码由 EJB 框架使用这一事实并不真正相关。
然而,EJB 2.x 是一个不同的(而且丑陋的)鱼缸,因为它不符合任何通常的软件设计规则。最好的选择可能是像 Cactus 这样的框架。
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.