且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用JUnit轻松测试EJB

更新时间:2023-12-04 21:32:40

我建议您查看 Arquillian


Arquillian使您可以在远程或嵌入式容器中测试业务逻辑。或者,它可以将存档部署到容器,以便测试可以作为远程客户端进行交互。


仍然有一个生活嵌入式JBoss AS Seam Framework 还提供了一个带有嵌入式JBoss的测试环境,以运行应用程序的组件测试(带有TestNG)。 p>

I want to test an enterprise java bean (that should later be deployed to a JBoss server) using JUnit. But I don't exactly know how tools I can use for this. Plain JUnit fails because of the missing EJB Container and the caused lack of needed injections.

Googling a bit around lead me to a library called JBoss EJB embedded container, but it seems that it is obsolete. I also couldn't find any source or binary files to download.

So please help, what's a easy way to locally generate a "mock" container that is able to run the JUnit tests on the enterprise beans?

Greetings Ben

I suggest you to have a look at Arquillian:

Arquillian enables you to test your business logic in a remote or embedded container. Alternatively, it can deploy an archive to the container so the test can interact as a remote client.

There is still a living Embedded JBoss AS. The Seam Framework also provides a testing environment with an embedded JBoss to run component tests (with TestNG) of your application.