Opentaps 2 Automated Testing

From Opentaps Wiki
Revision as of 22:29, 26 January 2012 by Oandreyev (talk | contribs) (opentaps 2 Automated Testing)
Jump to navigationJump to search

opentaps 2 Automated Testing

opentaps 2 supports both unit and integration testing.

Running the tests

To run unit tests:

mvn -DskipTests=false verify

To run integration tests:

mvn -Dit verify

To run both:

mvn -DskipTests=false -Dit verify

Also when running unit tests one can chose to run only one test, for example:

 mvn verify -DskipTests=false -Dtest=ValidationTest

where -Dtest=<name of the unit test classes (can be comma separated)>

Checking the tests results

Integration tests results can be checked in the maven output, but also each test output and the tests summary can be found at

 ./integration-tests/tests-run/target/failsafe-reports/

For unit tests, the output can be found for each module, for example at

 ./modules/notes/impl/tests/target/surefire-reports/


How to setup unit tests with Pax Exam

Because the integration tests runs Geronimo it can take quite some time to start and run, which can be discouraging when doing TDD or simply wanting to test a particular case.

As an example, in `./modules/notes/impl/tests/` is the module containing the unit tests for the `notes` module.

First is the Pax Exam configuration class:

./modules/notes/impl/tests/src/test/java/org/opentaps/notes/tests/NotesTestConfig.java 

Its role is to configure the OSGI environment in which the tests will be run by listing the bundles to be started. Some of those constitute an environment similar to what is provided by the Geronimo server : JPA, transactions, aries blueprint, apache bval, and their dependencies etc .. the others are the API and implementation bundles of the module we are testing.

Worth noting is the org.opentaps.validation.testimpl bundle which replaces org.opentaps.validation.impl during unit testing as a way to bootstrap and provide JSR303 validation.

Second are the JUnit style unit tests, they all extend the configuration class, for example:

./modules/notes/impl/tests/src/test/java/org/opentaps/notes/tests/NoteApiTest.java

The only particularities here are the @RunWith(JUnit4TestRunner.class) annotation which allows Pax Exam to run it as a JUnit unit test, and the @Inject annotations that will inject the OSGI services.