JPA2 Junit4 testing with HSQLDB as in-memory database
January 25, 2010Followed the steps from this great article –
Only issue is that this article uses EclipseLink instead of hibernate implementation of JPA.
If you are using Netbeans 6.8 and you generated the pom file for the project, please perform the following steps –
1. Comment out the following dependency
javax
javaee-api
6.0
provided
or
javax
javaee-web-api
6.0
provided
(depending upon the type of project you created, web or ejb)
2. Add the following exclusion from hibernate-entitymanager artifact
org.hibernate
ejb3-persistence
3. For latest bean validation jsr add the following artifact
org.glassfish
bean-validator
3.0-JBoss-4.0.2_02
and for the persistence apis add the following dependency
javax.persistence
persistence-api
1.0
4. Comment out ejb3-persistence api artifact
org.hibernate
ejb3-persistence
1.0.1.GA
But of course you would have to add the test level dependency for HSQLDB and update the Junit version from old 3.8.2 to latest 4.5
Also for DBunit and dates keep this note handy
DbUnit use the JDBC escape formats for string representation.
Type | Format |
---|---|
DATE | yyyy-mm-dd |
TIME | hh:mm:ss |
TIMESTAMP | yyyy-mm-dd hh:mm:ss.fffffffff |
Happy Testing
Leave a comment