在容器外部的 EJB 3.x 中对 Bean 管理的事务进行单元测试

发布于 2024-12-15 22:42:50 字数 479 浏览 0 评论 0原文

有没有一种好方法可以在容器外部的 EJB 3.x 中对 BMT 进行单元测试。我相信在我们编码时测试交易是有意义的。恕我直言,从第一个可能的阶段就测试我们的代码非常重要。因此,如果有一种简单且不需要太多时间执行的好方法来测试 BMT,那么将非常受欢迎。

目前,我正在使用内存数据库在容器外的 EJB 中测试我的 JPAQL。我使用unitils-DBUnit 将测试数据注入我的数据库中。那么,测试床设置好了,如果有特殊场景需要测试BMT,该怎么办呢?

PS:我已经研究过像 Bitronix 这样的工具,但我真的不确定是否这会对我的案子有帮助。我需要一些真正性能密集且轻便的工具,这样它就不会令开发人员感到沮丧——这就是单元测试。也请给我您对此的意见。根据您的说法,这样的工具对我的目的有好处吗?如果是的话,您还有什么例子可以参考吗?

多谢

Is there a good way to unit test BMT in EJB 3.x, outside the container. I believe that it would make sense to test transactions right when we are coding it. IMHO it is important to test what we code right from the first possible stage. So, if there is a nice way which is simple and does not take too much time to execute, to test BMT, then it would be really welcome.

At present, I am using an in-memory DB to test my JPAQL in EJB outside the container. I use unitils-DBUnit to inject test data in my DB. So, as the test bed is set, in special scenarios where I need to test the BMT, what should I do?

P.S : I have taken a look into tools like Bitronix, but I am really not sure if it would help my case. I need some tool that is really performance intensive and light so that it does not frustrate the developers - this is unit testing. Kindly give me your inputs on this too. According to you, would such a tool be good for my purpose. If yes, do you also have any examples that I can refer to?

Thanks a lot

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

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

发布评论

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

评论(2

っ左 2024-12-22 22:42:50

Do you really need to test "outside the container", or is "outside the server" sufficient? If the former, have you looked at the embeddable EJB container support in EJB 3.1? The embeddable EJB container runs in a standalone Java process (ideal for unit tests), and BMT is required for the embeddable EJB container per table 27 (section 21.1) of the EJB 3.1 spec.

感性 2024-12-22 22:42:50

对于单元测试事务,应该有一个完整的事务管理器,它是独立的并且执行时间非常少。它不应该强制部署任何 Bean 或 jar。

Bitronix 工作正常,满足我的目的。执行测试只需不到一秒的时间。因此,我不必再模拟我的事务,并且我可以确定事务在我的代码进入集成测试阶段之前按照我期望的方式工作。我也看到过有关 Atomikos 的积极回应,但我从未尝试过。也许当我评估 Atomikos 时我也可以更新这个线程。

For unit testing transactions, there should be a complete transaction manager which is standalone and takes very less time to execute. It should not force deployment of any beans or jars.

Bitronix is working fine and satisfies my purpose. It takes less than a second to execute the tests. So, I do not have to mock my transactions anymore and I can be sure that the transactions work as I expect them to work before my code moves to the Integration testing phase. I have also seen positive responses about Atomikos, but I never tried it. May be I can update this thread when I evaluate Atomikos too.

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