Build Status

Bean Testing for Java EE Applications using CDI

This project attempts to show an interesting approach on testing Java EE Applications. It uses a CDI Container to resolve dependencies like EJBs or Resources when running unit test in a standard environment.

The name "Bean Testing" is used, since it isn't about proper unit tests. However, the feedback speed is very close to unit test and the tests look undistinguishable too.

Main advantages:

Production ready

BeanTest is currently being used in some (big) customer projects. The projects are big Java EE Applications with several subsystems (.ear's). Each subsystem consists of several modules (.jar's) as well. We haven't faced any critical problem. Usually one can fix a problem by using standard CDI features.

Examples

You can find the examples about how a "Bean" test looks like under src/test/java (look for classes whose names begin with Test*)

How to use it


    <dependency>
      <groupId>info.novatec</groupId>
      <artifactId>bean-test</artifactId>
      <version>{currentVersion}</version>
      <scope>test</scope>
    </dependency>
    <repository>
       <id>Novatec</id>
       <name>Novatec Repository</name>
       <url>http://repository.novatec-gmbh.de/content/repositories/novatec</url>
    </repository>

Why you should use it

First of all, this approach is neither a replacement for unit nor integration tests. This approach is something in the middle.

You should always write unit tests for essential business logic.

You should always write integration tests to check that everything works as expected.

So, why use this approach? Because you get the best of both worlds: You get the speed of unit tests with almost the coverage of integration tests and all this with minimal configuration and with standard and well known frameworks like JPA, CDI, Mockito and Junit.

Since you don't need an application server for running your tests, you can integrate them in your normal unit test build process. In this way, you get almost integration test coverage in your normal builds.

Requirements

Contribute

Just fork.