EJB 3.1 嵌入式 API - 单元测试 EJB + JPA 实体
有没有人对现有项目做过或尝试这样做?
这里似乎有两个选项可以选择,要么使用 嵌入式 EJB API 基本上是以下类
javax.ejb.embeddable.EJBContainer
,它期望配置的 glassfish v3 安装可用(应用程序范围的资源将使这变得更容易)。
另一种方法是使用嵌入式 glassfish jar 文件和 嵌入式 glassfish API
我正在寻找已经或正在这样做的人的反馈,以及使用简单的 EJB 和博客链接等。测试用例多如牛毛。
如果您已经使用任何其他 EJB 3.1 容器完成了此操作,请随时分享。
- 除了您首选的工具之外,您是否出于其他原因使用任何特定的测试框架?
- 您使用了哪种 JPA 2.0 实现,这样做有什么特殊原因吗?
- 如果您使用 glassfish,您会使用上述哪种策略?如果没有,那么您使用了哪个 EJB 3.1 容器?
- 如果您成功地做到了这一点,是否值得付出努力?您会为另一个现有项目再次这样做吗?
Has anyone done this or attempted to do this for a preexisting project?
It seems there are two options to go with here, either using the embedded EJB API basically the following class
javax.ejb.embeddable.EJBContainer
Which expects a configured glassfish v3 install to be available (application scoped resources will make this easier).
The alternative is using the embedded glassfish jar files and the embedded glassfish API
I am looking for feedback from someone who has or who is in the process of doing this, links to blogs etc with a simple EJB & test case are dime a dozen.
If you've done this with any other EJB 3.1 container feel free to share.
- Did you use any particular test framework for reasons other than it been your preferred tool?
- Which JPA 2.0 implementation did you use, and was there a particular reason for doing so?
- If you used glassfish which of the above strategies did you use? If not then which EJB 3.1 container did you use?
- If you successfully did this, was it worth the effort and would you do this again for another existing project?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,您还可以在项目中使用最小域。
受 使用可嵌入的 GlassFish 对 EJB 和 JPA 进行单元测试。阅读它绝对是值得的。
没有。
我使用了EclipseLink(因为当时可用)。
我使用了嵌入式 EJB API,我计划在其他 Java EE 6 容器可用时在它们上运行我的代码。
嗯,我认为集成/功能测试很有价值,并且发现嵌入式 EJB API 对此非常有用。即使我不将我的示例视为现实生活中的项目,使用它也不是一件痛苦的事。
对于更复杂的场景,我会关注 maven-embedded-glassfish-plugin (另请参阅此答案)。
No, you can also use a minimal domain inside your project.
I've done integration testing of EJB 3.1 and JPA on my pet project (under Maven), inspired by Unit Testing EJBs and JPA with Embeddable GlassFish. Reading it is definitely worth it.
Nope.
I used EclipseLink (because it was available at that time).
I used the Embedded EJB API, I was planning to run my code on other Java EE 6 containers when they'll be available.
Well, I think that integration / functional testing have value and find that the Embedded EJB API is really nice for that. It was not a pain to use it even if I don't consider my sample as a real life project.
For more complex scenarios, I keep an eye on the maven-embedded-glassfish-plugin (see also this answer).
我在我的博客上写了一个 小教程 用于使用嵌入式 glassfish 3.1 使用
javax.ejb.embeddable.EJBContainer
对 EJB 进行单元测试。它有一些陷阱,我通过修改默认嵌入的 glassfish 域并将一些属性放入createEJBContainer()
调用来解决。I have written a small tutorial on my blog for using embedded glassfish 3.1 for unit-testing EJBs using
javax.ejb.embeddable.EJBContainer
. There are some pitfalls to it, which I got around by modifying the default embedded glassfish domain and putting some properties tocreateEJBContainer()
call.