Opentaps 2 Automated Testing

From Opentaps Wiki
Revision as of 23:48, 26 January 2012 by Oandreyev (talk | contribs) (Checking the tests results)
Jump to navigationJump to search

opentaps 2 Automated Testing

opentaps 2 supports both unit and integration testing.

Unit Tests

Running the tests

To run unit tests:

mvn -DskipTests=false verify

To run both unit tests and integration tests:

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

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.

Integration Tests

During integration testing opentaps bundles are combined into application, deployed to Geronimo instance and tested as integrated system.

Running the tests

In order to run this kind of tests you have to activate "it" profile with the following command line:

mvn -Dit verify

or

mvn -Dit -DgeronimoHome=/path/to/geronimo/dir verify

Note the difference. First command line uses fresh copy of Geronimo every run, second one uses a preinstalled Geronimo and is helpful if you want to test applications with extra configuration changes or modules not included into release distribution.

Also you can choose to run single test case

mvn -Dit -Dit.test=TestsClass verify

or even single test

 mvn -Dit -Dit.test=TestsClass#testMethod verify

Checking the tests results

Integration tests results can be checked in the maven output and a report at:

 ./integration-tests/tests-run/target/site/failsafe-report.html