else entirely. The Enterprise containers create and instantiate proxies for your EJBs, de-
pendencies are injected, configuration files ( web.xml , ejb-jar.xml ) further configure
the container, database connections are established, and much more. To make sure your
code is still functioning properly after all this, you need to move beyond unit testing and
into integration testing.
Integration testing is a strategy that tests your application's code in a way that closely mim-
ics a real environment but isn't quite a real environment. Its primary purpose is to ensure
that the interaction of your code with external resources is correct, and that when all of the
different technologies used in the application actually come together, they can function as
they're intended to. So what does this mean? Well, let's use a database as a simple example.
For your application to work properly, you need a database filled with the correct data. In
an integration testing strategy, you don't mock the data as you do in a unit test. Instead, the
test will most likely use an in-memory database that can be easily created and destroyed
for the lifecycle of the integration tests. An in-memory database is a real database so it'll
test your JPA entities and verify that they're working properly, but it's still not quite “real.”
The in-memory database mimic's the “real” external database for the purposes of the integ-
How does this relate to EJBs? Just as the database is mimicked for integration tests, the
EJB container needs to be mimicked for testing your EJBs. Just as there are in-memory
databases like Derby to mimic “real” databases like MySQL or Oracle, there's an embed-
ded EJBContainer that may be used to mimic a “real” Java EE server like GlassFish.
Let's take a look at this embedded EJBContainer .
The embedded EJBContainer is part of the EJB specifications and is required in a full
EJB implementation. We briefly introduced the embedded EJBContainer in chapter 5
as a way for EJBs to be used within Java SE applications. The embedded EJBContainer
can also be utilized by integration tests for testing EJBs. The integration test can start the
embedded EJBContainer in-memory, which will deploy all the EJBs it finds in the in-
tegration test's class path and then proceed with testing the EJBs. Although the embedded
EJBContainer is a tremendous resource, using it can be quite a challenge. This is where
technologies such as Arquillian come in.