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

查看:31
本文介绍了当前最好的单元测试框架 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.

一些资源

但是还有很多其他的很容易找到

But there are many others easily findable

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

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