Ejb3Unit - out of container EJB 3.0 testing - Automate your ejb3 testing NOW!
The Ejb3Unit project automates Entity and Session bean testing outside the container for the EJB 3.0 specification.
What are the features of ejb3unit?
- Ejb3Unit is a JUnit extention and can execute automated standalone junit tests for all EJB 3.0 conform JEE projects.
- The out of container test approach leads to short build-test-cycles, because no container deployment is necessary anymore.
- EJb3Unit uses an internal in memory database by default. Alternatively a user defined database can be specified. An example configuration can be found here.
- Ejb3unit is released under the LGPL License.
Ejb3Unit 2.0 is out now
See our Roadmap for a full feature list.
Announcement: Ejb3Unit is powering jp-mobile !!!
Java Platform Mobile jp-mobile is a unified, HTML5-based user interface system for all popular mobile device platforms, built on the rock-solid GWT foundation. Its lightweight code is built with progressive enhancement, and has a flexible, easily themeable design. Jp-mobile provides the right toolset developing mobile applications with GWT and works on all kind of mobile devices that support webkit (like iPhone, iPad, iPod, Android, Blackberry, ...). Try out our Java Platform Mobile jp-mobile showcase.
Overview of Test Cases in Ejb3Unit
Ejb3Unit uses 4 different base test classes. Base entity fixture for example allows to automate tests for persistence classes. The following matrix shows all available test classes together with their use case description:
Feature matrix of Test Cases in Ejb3Unit
You can create and test entity beans outside a JEE 5, EJB3 container.
- Fully automated test
- Entity beans are randomly (or customized) written against and read from an in memory database (or against a database you may specify). This can easily be parametrizied to your own needs.
- equals() and hashCode() methods implementations of your Entity beans are checked automatically.
- Nullable fields are tested.
- Possible data truncations or possible schema errors will be checked.
- Manual test
- Of course you can add manual tests if you like
- Relations: OneToMany and ManyToOne supported
- With Ejb3Unit its possible to Test this beans AND the relations (in a non transitive way!).
- Limitations:
- ManyToMany relations, OneToOne relations and unidirectional relationships are currently not supported. For this or complex scenarios you can use the "PoJoFixture" which setups the infrastructure and gives you access to an entity manager which allows to persist your own object graph.
- Currently only the access type 'field' is supported (annotation are declared on the field). The access type 'property' (annotation are declared on the methods) is currently not supported.
This test represents an integration test, if you like to test parts of your system in collaboration.
- The session bean under test and all referenced session beans are created.
- Also a DataSource, EntityManager and a SessionContext are injected.
- The in memory database is initialized with predefined data using comma separated value files. Each .csv file represents data for one table (using the mapping definitions form the corresponding entity bean). The testdata can also be defined directly in the testclass if this is necessary.
POJO test is the alrounder for testing any POJO (Plain Old Java Object) which would be normally executed inside the container. Test complex object graphs or complex queries.
The POJO fixture provides access to the entity manager, it creates the schema for you if you are using Ejb3Unit with the in memory database and provides helper methods to persist and generate random instances of your persistent objects.
A session bean class is created and for all dependencies mock objects are injected. This test allows testing of an Session bean in isolation.
- A mock object is a substitute for a concrete implementation (please see JMock for details).
- All EJB 3.0 dependency injection attributes are supported.