Is there a way to prevent Maven Test from rebuilding the database?

Posted by Christopher W. Allen-Poole on Stack Overflow See other posts from Stack Overflow or by Christopher W. Allen-Poole
Published on 2010-02-18T20:57:46Z Indexed on 2010/05/21 19:40 UTC
Read the original article Hit count: 295

Filed under:
|
|
|

I've recently been asked to, effectively, sell my department on unit testing. I can't tell you how excited this makes me, but I do have one concern. We're using JUnit with Spring and Maven, and this means that each time mvn test is called, it rebuilds the database. Obviously, we can't integrate that with our production server -- it would kill valuable data.

How do I prevent the rebuilding without telling maven to skip testing?

The best I could figure was to assign the script to operate in a test database (line breaks added for readability):

mvn test 
   -Ddbunit.schema=<database>test 
   -Djdbc.url=jdbc:mysql://localhost/<database>test?
        createDatabaseIfNotExist=true&amp;
        useUnicode=true&amp;characterEncoding=utf-8 

I can't help but think there must be a better way.

I'm especially interested in learning if there is an easy way to tell Maven to only run tests on particular classes without building anything else? mvn -Dtest=<test-name> test still rebuilds the database.

======= update =======

Bit of egg on my face here. I didn't realize that I was using the same variable in two places, meaning that the POM was using a "skip.test" variable for both rebuilding the database and for running the tests...

© Stack Overflow or respective owner

Related posts about java

Related posts about maven-2