1

I am working currently with the theme of testing EJBs in the version 3.1 and I do have only some experience with it. So I take look at the literature and found out three different ways/methods of testing EJBs (Version 3.0 and newer)

1) Use of simple POJT (Plain Old Java Tests)

2) Use of an embedded Container

3) Test of the application in the application server

After I figured out these the different methods I started some research on my own and found out some possibilities.

For case 1) tools like JUnit or TestNG are nearly perfect and to solve the problems of the annotations the library EasyGloss can be used. For very simple beans EasyGloss isn't necessary. The "local" testing works fine until the bean need access to Contexts (e.g. sessionContext), uses Transactions or Interceptors.

I use JBoss AS 7.1.1 and as far as I know this application server doesn't provide an embedded Container. So I can switch to Glassfish (what I do not prefer) or use some alternatives like OpenEJB or Arquillian to handle tests for case 2).

I know that you guys have a lot more experience and knowledge of testing Jave EE and EJBs. So I want to ask you if you would share your experience with me and maybe give some tips and tricks, more thoughts or example code of efficient tests of ejbs.

Edit: Added more informations für case 1).

FredFloete
  • 627
  • 2
  • 13
  • 33
  • 1
    If you're looking for the embedded Arquillian container for AS7, [it's been merged into the master branch](https://issues.jboss.org/browse/AS7-974). I'm not sure when it would be released. Note, this is conceptually different from the EJB 3.1 embedded container, whose usage notes are [here](https://community.jboss.org/wiki/EJB31Embeddable). – Vineet Reynolds Nov 04 '12 at 09:49

2 Answers2

1

An embedded container is a part of EJB 3.1, so even JBoss AS 7 has to implement it.

Arquillian is a very good option as well, and since AS 7 starts so fast the extra overhead of an external AS is not that much.

You can also combine Arquilluan with the embedded container that AS 7 should offer.

Mike Braun
  • 3,729
  • 17
  • 15
1

As Vineet pointed out there is a JBoss Embedded Container. However, as long as you do not use AS specific classes there should not be a problem when using the embedded Glassfish container (here is an easy example). Embedded containers are especially interesting if you do use the provided EJB infrastructure intensively; as you mentioned Interceptors, Transactions etc. Otherwise the advantage compared to plain unit testing is not that big.

When testing your application in the application server and your components are Remote Beans you can test them directly via JNDI lookup in your Unit Test; you can also integrate Remote Beans as testing hooks. However, Arquillian is especially interesting in case you want to test CDI or Local beans, as you cannot access them remotely.

I think it is essential to compare a tool/technology like embedded container or Arquillian to plain unit testing. Is there a big advantage? Are there any tests I cannot cover without the tool? Just because something is new and cool does not mean you necessarily benefit from it :)