views:

47

answers:

2

I'm using maven war plugin to build war package.

Before package is build test are executed. To preinitialize my database with sample data I use spring bean. I would like to have different data in my db for tests and different when application starts.

I was thinking that maybe it is possible to use two different spring initializer classes in 'test' and 'war' phases but I don't know how to achieve this.

+3  A: 

You have to put the different classes you need into src/main/java or src/test/java or may be supplemental application.xml into src/main/resources or src/test/resources. The test initializer can be done by a Test class which initializes first before all tests are running (take a look at testng which has this kind of feature).

khmarbaise
This works because Maven automatically adds src/main/java, src/test/java and src/test/resources to the classpath when running tests and only adds src/main/java and src/main/resources to the WAR.
Chris Nava
+1  A: 

Your tests should not be using the production Spring context (xml) files.

Instead, if you need to access an ApplicationContext in your tests (or if you are using a base testcase class like AbstractTransactionalJUnit4SpringContextTests), set up a test-context.xml context which points to the test database configuration and the test data scripts.

matt b