简体   繁体   English

Glassfish上本地EJB的集成测试

[英]Integration test of local EJB on Glassfish

I am a little confused about integration testing of a simple EJB. 我对简单EJB的集成测试有点困惑。 If I want to test the EJB's local interface/no-interface do I need to use Arquillian? 如果我想测试EJB的本地接口/无接口,我是否需要使用Arquillian? I stumbled upon Arquillian but I have never used it. 我偶然发现了Arquillian,但我从未使用它。 I have a Maven directory structure/Glassfish and Eclipse Indigo 我有一个Maven目录结构/ Glassfish和Eclipse Indigo

If I want to test the EJB's local interface/no-interface do I need to use Arquillian? 如果我想测试EJB的本地接口/无接口,我是否需要使用Arquillian?

It is not necessary to use Arquillian, but there are certain things made easier when you do so. 没有必要使用Arquillian,但是当你这样做时,某些事情变得更容易。

Ordinarily, you would merely use the EJBContainer API available in EJB 3.1 for testing of EJBs in an embedded container (that runs in the same JVM as the tests). 通常,您只需使用EJB 3.1中提供的EJBContainer API来测试嵌入式容器中的EJB(在与测试相同的JVM中运行)。 In the case of embedded Glassfish, this typically results in deployment of EJBs that are found in the classpath of the application. 对于嵌入式Glassfish,这通常会导致部署在应用程序的类路径中的EJB。

Arquillian allows you to do a lot more than execute tests in a container. Arquillian允许您做的不仅仅是在容器中执行测试。 It manages the lifecycle of the container, thus not requiring any writing of code beyond setting the properties in the arquillian.xml file. 它管理容器的生命周期,因此除了在arquillian.xml文件中设置属性之外,不需要编写任何代码。 It allows you to manage deployments to a container in a far more easier manner; 它允许您以更容易的方式管理容器的部署; using the ShrinkWrap API, one can programmatically perform different context-sensitive deployments to a container. 使用ShrinkWrap API,可以以编程方式对容器执行不同的上下文相关部署。 Furthermore, injection of dependencies (test enrichment) can also be performed, so long as they're supported by Arquillian. 此外,只要它们得到Arquillian的支持,也可以执行依赖注入(测试丰富)。

It would suffice to know that the embedded Glassfish container support for Arquillian, uses the same APIs that are exposed by the embedded Glassfish API; 只需知道嵌入式Glassfish容器支持Arquillian,就可以使用嵌入式Glassfish API公开的相同API; usually you might end up duplicating the work of Arquillian, except in certain unique scenarios. 通常你可能最终会复制Arquillian的工作,除非在某些独特的场景中。

If you're interested in taking a look at examples using Arquillian, this GitHub project would help. 如果您有兴趣看看使用Arquillian的示例, 这个GitHub项目会有所帮助。

When you are not a fan of mocking (just like me), then you could either have a look at ejb3unit (http://ejb3unit.sourceforge.net/), or try Arquillian. 如果你不是嘲笑的粉丝(就像我一样),那么你可以看一下ejb3unit(http://ejb3unit.sourceforge.net/),或试试Arquillian。

I must say I had very good experiences with "ejb3unit". 我必须说我对“ejb3unit”有很好的体验。

But it seems that "EJB3unit" peoject was not maintenance since 2-3 years. 但似乎“EJB3unit”项目自2 - 3年以来一直没有维护。 But supprisingly, weeks ago, there are again some activities on the ejb3unit site. 但令人遗憾的是,几周前,ejb3unit网站上又有一些活动。

Arquillian is not so easy start with. Arquillian开始并不是那么容易。 I would say this mainly lies in the documentation, missing running examples, and good turorials. 我会说这主要在于文档,缺少运行示例和良好的语言。

But so long as you have made your firt Arquillian test run, Arquillian begins to shine! 但是只要你完成了Arquillian试运行,Arquillian就会开始闪耀!

Under the following link, you could find a tutorial serial on step by step setting up Arquillian: 在以下链接中,您可以找到一个逐步设置Arquillian的教程序列:

http://milestonenext.blogspot.de/2012/12/ejb3-integration-test-with-arquillian.html http://milestonenext.blogspot.de/2012/12/ejb3-integration-test-with-arquillian.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM