Running Unit Tests

Cayenne provides a comprehensive suite of unit tests. To execute unit tests you must first get Cayenne from Git, install JDK 1.7 and obtain the latest Maven.


Maven build prerequisites and recommended settings apply here.

Running Against Embedded HSQLDB

No extra setup is required. Just run Maven:

$ cd cayenne
$ mvn install


$ cd cayenne
$ mvn clean verify

Running Against In-memory Database

Besides HSQLDB mentioned above Cayenne has preconfigured connection information for following databases that support in-memory mode:

  • derby
  • h2
  • sqlite

For this databases you can run tests without any additional configuration by only specifying cayenneTestConnection property that will activate required Maven profile:

$ mvn verify -DcayenneTestConnection=derby

Running Against Database in Docker (only on Linux)

Another handy option to run Cayenne tests is with preconfigured docker profiles. The only thing you need is to install Docker.

You can run tests with following cayenneTestConnection properties:

$ mvn verify -DcayenneTestConnection=mysql-docker


$ mvn verify -DcayenneTestConnection=postgres-docker

Running Against a Specific Database

Final option to run tests against any supported database is with manual configuration.

Step 1. Install JDBC Driver Jars in a Local Maven Repo

Most commercial drivers are not present in the public Maven repositories. So they have to be installed by the tester locally. The group and artifact ids are arbitrarily assigned in the main Cayenne POM, so users must follow the POM or the examples below.


$ mvn install:install-file -Dfile=frontbasejdbc.jar -DgroupId=com.frontbase \
       -DartifactId=frontbase-driver -Dversion=4.1 -Dpackaging=jar -DgeneratePom=true


$ mvn install:install-file -Dfile=OpenBaseJDBC.jar -DgroupId=com.openbase \
       -DartifactId=openbase-driver -Dversion=9 -Dpackaging=jar -DgeneratePom=true


$ mvn install:install-file -Dfile=ojdbc5.jar \
       -DartifactId=oracle-driver -Dversion=11 -Dpackaging=jar -DgeneratePom=true


$ mvn install:install-file -Dfile=sqljdbc4.jar \
       -DartifactId=sqlserver-driver -Dversion=4.0 -Dpackaging=jar -DgeneratePom=true


$ mvn install:install-file -Dfile=jconn3.jar -DgroupId=com.sybase \
       -DartifactId=sybase-driver -Dversion=12 -Dpackaging=jar -DgeneratePom=true

Step 2. Run Tests Against Configured Data Source

Database type and connection information can be specified either on the command line or via a configuration file. First let's look at the command line options:

$ mvn verify -DcayenneTestConnection=<profile_name> \
   -DcayenneAdapter=org.apache.cayenne.dba.mysql.MySQLAdapter \
   -DcayenneJdbcUsername=myuser \
   -DcayenneJdbcPassword=mypassword \
   -DcayenneJdbcUrl=jdbc:mysql://localhost/cayenne \

cayenneTestConnection is a property activating a DB-specific Maven profile. can be one of:

  • db2
  • derby
  • firebird
  • frontbase
  • h2
  • ingres
  • mysql
  • openbase
  • oracle
  • postgres
  • sqlite
  • sqlserver
  • sybase

Another way to store this information permanently for each profile is to create a directory $HOME/.cayenne/ and place a file called in this directory. File contents should be similar to this example:

mysql.cayenne.adapter = org.apache.cayenne.dba.mysql.MySQLAdapter
mysql.jdbc.username = someuser
mysql.jdbc.password = somepasswd
mysql.jdbc.url = jdbc:mysql://
mysql.jdbc.driver = com.mysql.jdbc.Driver

oracle.cayenne.adapter =
oracle.jdbc.username = someuser
oracle.jdbc.password = somepasswd
oracle.jdbc.url = jdbc:oracle:thin:@//
oracle.jdbc.driver = oracle.jdbc.driver.OracleDriver

postgres.adapter = org.apache.cayenne.dba.postgres.PostgresAdapter
postgres.jdbc.username = someuser
postgres.jdbc.password = somepasswd
postgres.jdbc.url = jdbc:postgresql://
postgres.jdbc.driver = org.postgresql.Driver

db2.adapter = org.apache.cayenne.dba.db2.DB2Adapter
db2.jdbc.username = someuser
db2.jdbc.password = somepasswd
db2.jdbc.url = jdbc:db2://
db2.jdbc.driver =

Each property starts with the Maven profile name ("mysql" and "oracle" in the example above). Note that in this case you should still use cayenneTestConnection. E.g.:

$ mvn verify -DcayenneTestConnection=mysql