Use an alternate Maven profile during testing

I am trying to build an application starting with Archetype Appfuse, but I am having some strange problems. This time I would like to use hsqldb for automatic unit tests and integration tests and mysql db for my manual testing so that I can easily manipulate the data when I need it, so it would be nice to automatically switch profiles during the testing phase. Is there any way to do this?

+3
java unit-testing maven-2 appfuse
source share
2 answers

I'm not sure if this is exactly what you are asking for, but you can do the following to set up several filters for your Maven project.

<filters> <filter>/your/path/filter-${env}.properties</filter> </filters> 

This way you can configure multiple profiles using:

 <profiles> <profile> <id>local</id> <properties> <env>local</env> </properties> </profile> <profile> <id>test</id> <properties> <env>test</env> </properties> </profile> </profiles> 

Then you can start the assembly with the appropriate properties file using:

 mvn -P <profile id> 

This will require the presence of property files located at:

 /your/path/filter-local.properties /your/path/filter-test.properties 
+7
source share

Not sure if this can help you at all, but you can specify alternative resource files in the / src / test / resources folder that override the ones in / src / main / resources when you run the tests.

I am defining an alternative placeholders.properties file here to specify a different db connection that will be used during the testing phase.

+2
source share

All Articles