最新的EJB3 / JPA单元测试框架 [英] Best current framework for unit testing EJB3 / JPA

查看:128
本文介绍了最新的EJB3 / JPA单元测试框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用EJB 3 / JPA启动新项目,主要是无状态会话bean和批处理作业。我过去在标准的Java webapps上使用过JUnit,它看起来效果很好。在EJB2中,单元测试很痛苦,并且需要一个运行容器(如JBoss)来进行调用。既然我们将在EJB3 / JPA中工作,我想知道公司正在使用什么来编写和运行这些测试。 Junit和JMock是否仍然被认为是相关的,还是有其他新的框架,我们应该调查?

Starting a new project using EJB 3 / JPA, mainly stateless session beans and batch jobs. I've used JUnit in the past on standard Java webapps and it seemed to work pretty well. In EJB2 unit testing was a pain and required a running container such as JBoss to make the calls into. Now that we're going to be working in EJB3 / JPA I'd like to know what companies are using to write and run these tests. Are Junit and JMock still considered relevant or are there other newer frameworks that have come around that we should investigate?

推荐答案

恕我直言,是的它们仍然相关。

IMHO, yes they are still relevant.

使用EJB3,您可以像常规POJO一样测试EJB,也可以使用嵌入式EJB容器作为托管bean测试EJB。

With EJB3, you can test you EJB either like regular POJO, or as managed bean using an embedded EJB container.

对于JPA,您可以为测试嵌入JPA实现并使用内存数据库,也可以完全模拟数据层。

Same for JPA, you can either embed a JPA implementation for your test and use an in-memory database, or you can mock the data layer completely.

对于我上一个EJB项目,我写了一些胶合代码来测试EJB,因为嵌入式EJB容器还不够成熟,但现在我会选择嵌入式EJB容器+ JUnit。

For my last EJB project I had written a bit of glue code to test the EJB because embedded EJB container were not mature enough, but now I would go for an embedded EJB container + JUnit.

一些资源

  • Blog post: How to unit test EJB 3 in 0.8 seconds
  • SO question: Good unit testing resource for EJB

但还有很多其他人很容易找到

But there are many others easily findable

这篇关于最新的EJB3 / JPA单元测试框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆