Running Unit Tests has been edited by Tore Halset (Oct 15, 2007).

Change summary:

h4 -> h2 for looking at test results

(View changes)

Content:

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

Running Against Embedded HSQLDB

No extra setup is required. Just run Maven:

$ cd cayenne
$ mvn install

or


$ cd cayenne
$ mvn clean test

Running Against a Specific Database

Step 1: Configure One or More Data Sources

If you've already run the unit tests with the legacy ant builds, you may adapt the existing configuration, but connection entry names now must match the names in the Cayenne pom.xml. (If you were doing it for Cayenne 1.2, you will need to rename adapters from org.objectstyle to org.apache under "~/.cayenne/connection.properties". Otherwise create a directory $HOME/.cayenne/ and place a file called connection.properties 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 = ""
mysql.jdbc.driver = com.xyz.MyDriverClass

oracle.cayenne.adapter = org.apache.cayenne.dba.oracle.OracleAdapter
oracle.jdbc.username = someuser
oracle.jdbc.password = somepasswd
oracle.jdbc.url = ""
oracle.jdbc.driver = com.xyz.MyDriverClass

Each key starts with an identifier for a DataSource that must match a Maven profile defined in the Cayenne pom.xml. Currently valid profiles include:

  • derby
  • frontbase
  • mysql
  • openbase
  • oracle
  • postgres
  • sqlite
  • sqlserver
  • sybase

Step 2. 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.

FrontBase:

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

OpenBase:

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

Oracle:

$ mvn install:install-file -Dfile=ojdbc14.jar -DgroupId=com.oracle \
       -DartifactId=oracle-driver -Dversion=10 -Dpackaging=jar -DgeneratePom=true

SQLite:

$ mvn install:install-file -Dfile=sqlitejdbc-v037-nested.jar -DgroupId=org.sqlite \
       -DartifactId=sqlite-driver -Dversion=0.37 -Dpackaging=jar -DgeneratePom=true

SQLServer 2005:

$ mvn install:install-file -Dfile=sqljdbc.jar -DgroupId=com.microsoft \
       -DartifactId=sqlserver-driver -Dversion=2005 -Dpackaging=jar -DgeneratePom=true

Sybase:

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

Step 3. Run Tests Against Configured Data Source

To activate a corresponding Maven profile, use "-Dcayenne.test.connection=name" property. E.g. to test against MySQL:

$ mvn test -Dcayenne.test.connection=mysql

Note that profiles are activated when run from either root of Cayenne Maven structure or from individual module directories.

Look at test results

To look for failed tests, grep the output files.

$ grep FAIL framework/cayenne-jdk1.4-unpublished/target/surefire-reports/*.txt

Reply via email to