EJB 3.1 嵌入式 API - 单元测试 EJB + JPA 实体

发布于 2024-08-31 13:39:32 字数 751 浏览 6 评论 0原文

有没有人对现有项目做过或尝试这样做?
这里似乎有两个选项可以选择,要么使用 嵌入式 EJB API 基本上是以下类

javax.ejb.embeddable.EJBContainer

,它期望配置的 glassfish v3 安装可用(应用程序范围的资源将使这变得更容易)。

另一种方法是使用嵌入式 glassfish jar 文件和 嵌入式 glassfish API

我正在寻找已经或正在这样做的人的反馈,以及使用简单的 EJB 和博客链接等。测试用例多如牛毛。

如果您已经使用任何其他 EJB 3.1 容器完成了此操作,请随时分享。

  1. 除了您首选的工具之外,您是否出于其他原因使用任何特定的测试框架?
  2. 您使用了哪种 JPA 2.0 实现,这样做有什么特殊原因吗?
  3. 如果您使用 glassfish,您会使用上述哪种策略?如果没有,那么您使用了哪个 EJB 3.1 容器?
  4. 如果您成功地做到了这一点,是否值得付出努力?您会为另一个现有项目再次这样做吗?

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.

  1. Did you use any particular test framework for reasons other than it been your preferred tool?
  2. Which JPA 2.0 implementation did you use, and was there a particular reason for doing so?
  3. If you used glassfish which of the above strategies did you use? If not then which EJB 3.1 container did you use?
  4. If you successfully did this, was it worth the effort and would you do this again for another existing project?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

柠北森屋 2024-09-07 13:39:32

这里似乎有两个选项可供选择,要么使用嵌入式 EJB API (...),该 API 需要配置的 glassfish v3 安装可用。

不,您还可以在项目中使用最小域。

我正在寻找已经或正在这样做的人的反馈,以及使用简单的 EJB 和博客链接等。测试用例多如牛毛。

使用可嵌入的 GlassFish 对 EJB 和 JPA 进行单元测试。阅读它绝对是值得的。

除了您首选的工具之外,您是否出于其他原因使用任何特定的测试框架?

没有。

您使用了哪种 JPA 2.0 实现,这样做有什么特殊原因吗?

我使用了EclipseLink(因为当时可用)。

如果您使用 glassfish,您会使用上述哪种策略?如果没有,那么您使用了哪个 EJB 3.1 容器?

我使用了嵌入式 EJB API,我计划在其他 Java EE 6 容器可用时在它们上运行我的代码。

如果您成功地做到了这一点,是否值得付出努力?您会为另一个现有项目再次这样做吗?

嗯,我认为集成/功能测试很有价值,并且发现嵌入式 EJB API 对此非常有用。即使我不将我的示例视为现实生活中的项目,使用它也不是一件痛苦的事。

对于更复杂的场景,我会关注 maven-embedded-glassfish-plugin (另请参阅此答案)。

It seems there are two options to go with here, either using the embedded EJB API (...) which expects a configured glassfish v3 install to be available.

No, you can also use a minimal domain inside your project.

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.

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.

Did you use any particular test framework for reasons other than it been your preferred tool?

Nope.

Which JPA 2.0 implementation did you use, and was there a particular reason for doing so?

I used EclipseLink (because it was available at that time).

If you used glassfish which of the above strategies did you use? If not then which EJB 3.1 container did you use?

I used the Embedded EJB API, I was planning to run my code on other Java EE 6 containers when they'll be available.

If you successfully did this, was it worth the effort and would you do this again for another existing project?

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).

允世 2024-09-07 13:39:32

我在我的博客上写了一个 小教程 用于使用嵌入式 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 to createEJBContainer() call.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文