2011/01/16 - Apache ObJectRelationalBridge has been retired.

For more information, please explore the Attic.


JUnit Test Suite


Building an Object/Relational mapping tool with support for multiple API's is really error prone. To create a solid and stable software, the most awful thing in programmers life has to be done - Testing.

Quality assurance taken seriously! OJB and provide specific tests for each supported API. Currently more than 800 test cases for regression tests exist. As testing framework JUnit was used.

Where can I find the test sources?

The test sources of the OJB Test-Suite can be find under [db-ojb]/src/test/org/apache/ojb.
It's also possible to browse the test sources online using the OJB SVN view. The test directory can be found here: [db-ojb]/src/test/org/apache/ojb.

How to run the Test Suite

If the platform depended settings are done, the test suite can be started with the ant target:

ant junit

If compiling of the sources should be skipped use

ant junit-no-compile

If you did not manage to set up the target database with the ant prepare-testdb you can use

ant junit-no-compile-no-prepare

to run the testsuite without generation of the test database (and without compiling).

After running the regression tests you should see a console output similar to this:

    [junit] Running org.apache.ojb.broker.AllTests
    [junit] Tests run: 620, Failures: 0, Errors: 0, Time elapsed: 81,75 sec
    [junit] Running org.apache.ojb.odmg.AllTests
    [junit] Tests run: 183, Failures: 0, Errors: 0, Time elapsed: 21,719 sec
    [junit] Running org.apache.ojb.soda.AllTests
    [junit] Tests run: 3, Failures: 0, Errors: 0, Time elapsed: 7,641 sec
    [junit] Running org.apache.ojb.otm.AllTests
    [junit] Tests run: 79, Failures: 0, Errors: 0, Time elapsed: 28,266 sec

Total time: 3 minutes 26 seconds

We aim at shipping that releases have no failures and errors in the regression tests! If the Junit tests report errors or failures something does not work properly! There may be several reasons:

  • You made a mistake in configuration (OJB was shipped with settings pass all tests). See platform, OJB.properties, repository file, .
  • Your database doesn't support specific features used by the tests
  • Evil hex
  • Bug in OJB

JUnit writes a log-file for each tested API. You can find the logs under [db-ojb]/target/test. The log files named like tests-XXX.txt. The test logs show in detail what's going wrong.

In such a case please check again if you followed all the above steps. If you still have problems you might post a request to the OJB user mailinglist.

How to run the test-suite with a different database than OJB default DB

Basically all you have to do is:

  • Get source version of OJB or fetch OJB from CVS (take care of branches, branch OJB_1_0_RELEASE represents OJB 1.0.x).
  • Adapt the profile file of your database under [db-ojb]/profile/yourDB.profile and set user, password, ...
  • In [db-ojb]/build.properties file comment the "profile=hsqldb" line and uncomment the "#profile=yourDB" line.
  • Drop jdo.jar and your database driver into [db-ojb]/lib directory.
  • Drop junit.jar into your ...ant/lib folder.
  • Make sure that your database allows at least 20 concurrent connections.

Then follow the steps described above.

What about known issues?

All major known issues are listed in the release-notes file.
The tests reproduce open bugs will be skipped on released OJB versions. It is possible to enable these tests to see all failing test cases of the shipped version by changing a flag in [db-ojb]/build.properties file:

# If 'true', junit tests marked as known issue in the junit-test
# source code (see OJBTestCase class for more detailed info) will be
# skipped. Default value is 'true'. For development 'false' is recommended,
# because this will show unsolved problems.

Donate own tests for OJB Test Suite

Details about donate own test to OJB you can find here.

by Armin Waibel, Thomas Mahler