INTEGRATION TEST IN ECLIPSE WITH EMBEDDED OPENEJB
The embedded OpenEJB server will use an in-memory HSQLDB database. The significance of in-memory is that it will start empty and be discarded afterwards.
We specify the database in business/src/test/conf/openejb.xml, and we will set system property openejb.configuration to that file.
- Choose Run > Run Configurations.... The Run Configurations window will appear.
- Right-click on JUnit and choose New.
- Set Test Runner to JUnit 4.
- Set the other variables to values similar to those in the screen shot on the right.
|
|
- Click on the Arguments tab.
- Set the VM arguments to the following, replacing the value of openejb.home with yours, eg.:
-Djumpstart.ejb-provider=OPENEJB_7_LOCAL -Dlog4j.configurationFile=log4j.properties -Dopenejb.configuration=business/src/test/conf/openejb-in-memory.xml -Dopenejb.home=/devel/apache-openejb-7.0.4 -Dhibernate.hbm2ddl.auto=update
-
The openejb-in-memory.xml file configures openejb to use a different database: an in-memory database.
These properties are explained here:
openejb,
hibernate.
|
|
- Click on the Classpath tab.
- Remove the
(default classpath) entry.
- Click on User Entries.
- Add these 2 folders (Advanced... > Add folders):
business/src/test/conf/
collapsed/jumpstart.war/WEB-INF/classes/
- Add all JARs from these folders:
business/src/main/lib-compile/
business/src/main/lib-runtime/ (actually, lib-runtime is empty)
business/src/test/lib-test/
business/src/test/lib-test-hibernate/
- Add 1 user library (Advanced... > Add Library > User Library):
apache-openejb-7.0.4-lib
- Ensure the two folders are at the top. It avoids conflicts.
|
|
- Click Run.
- Watch the results in the JUnit View panel. In the Console View you might see lots of exceptions but that's normal.
The JUnit View will tell you quickly whether the tests succeeded or not.
- Problems? Eclipse might not be ready for junit - see
Could not create task or type of type: junit .