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

标签 java unit-testing jpa ejb-3.1 jpa-2.0

有没有人为已有的项目这样做过或试图这样做过?
似乎这里有两种选择,要么使用 embedded EJB API基本上是下面的类

javax.ejb.embeddable.EJBContainer

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

替代方法是使用嵌入式 glassfish jar 文件和 embedded glassfish API

我正在寻找已经或正在这样做的人的反馈,带有简单 EJB 和测试用例的博客链接等一毛钱一打。

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

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

最佳答案

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.

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

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.

我已经在我的宠物项目(在 Maven 下)上完成了 EJB 3.1 和 JPA 的集成测试,灵感来自 Unit Testing EJBs and JPA with Embeddable GlassFish .阅读它绝对是值得的。

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?

我使用的是 EclipseLink(因为它当时可用)。

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

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

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

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

对于更复杂的场景,我会关注 maven-embedded-glassfish-plugin (另请参见 this answer)。

关于java - EJB 3.1 嵌入式 API - 单元测试 EJB + JPA 实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2774500/

相关文章:

java - Android 应用程序 - 当我调试应用程序时,工具栏消失了

java - 可供使用的 SIP 客户端 Java 小程序

c# - 使用模拟(Moq)对象更改 Autofac 模块中的注入(inject)

c# - 模拟 HttpRequestException 进行单元测试

spring - 排除 hibernate 创建的特定表?

spring - 对依赖于@OneToMany 集合的类进行单元测试

java - 如何在 Spring Boot 应用程序中手动注册非标准化 SQL 函数?

java - 是否应该有很多 onTouchListener?

java - 哪一个更可取以及为什么

java - 如何在 Mockito 中模拟方法参数