开发者

Maven - use different java classes during 'test' and 'war' phase

开发者 https://www.devze.com 2023-01-05 13:58 出处:网络
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

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 开发者_如何学C'test' and 'war' phases but I don't know how to achieve this.


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).


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消