Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven: Running the same tests for different configurations

In my spring + maven app, I have created some tests for the Data Access Layer that I would like now to run against multiple datasources. I have something like:

@ContextConfiguration(locations={"file:src/test/resources/testAppConfigMysql.xml"})
public class TestFooDao extends AbstractTransactionalJUnit38SpringContextTests {
  public void testFoo(){
     ...
  }
} 

It has currently the config location hardcoded, so it can be used only against one datasource. What is the best way to invoke the test twice and pass two different configs (say testAppConfigMysql.xml and testMyConfigHsqlDb.xml)?

I've seen suggestions to do this via system properties. How can I tell maven to invoke the tests twice, with different values of a system property?

like image 352
jfu Avatar asked Nov 13 '22 06:11

jfu


1 Answers

I don't know if there is some sexy and fancy solution, being simple as well, for this. I would just implement base class with all testing stuff and then inherit it into 2 classes with different annotation-based configuration, like this:

@ContextConfiguration(locations={"firstDs.xml"})
public class TestFooDaoUsingFirstDs extends TestFooDao {
}

@ContextConfiguration(locations={"secondDs.xml"})
public class TestFooDaoUsingSecondDs extends TestFooDao {
}

Unless you have to handle really high number of different datasources this way, that is OK for me.

like image 153
Michał Kalinowski Avatar answered Dec 08 '22 00:12

Michał Kalinowski