Reputation: 114777
I want to test some code with different persistence units. Therefor I have written two identical TestNG test classes that only differ in the name of the persistence unit that I pass to Persistence#createEntityManagerFactory
to get the correct factory.
This call is in a setup method annotated with `@BeforeClass``
@BeforeClass
public void setupClass() {
emf = Persistence.createEntityManagerFactory("test-eclipselink-h2");
em = emf.createEntityManager();
// init with some dummy data
// ... some more initialization
}
What are the options to execute this test class with different persistence-units? It would be sufficient to have the names hardcoded in test classes, there is no need to specify them externally.
Upvotes: 0
Views: 1378
Reputation: 15608
public class A {
private String s;
@DataProvider
public Object[][] dp() {
return new Object[][] {
new Object[] { "test-eclipselink-h1" },
new Object[] { "test-eclipselink-h2" }
};
}
@Factory(dataProvider = "dp")
public A(String s) {
System.out.println("Creating test class with " + s);
this.s = s;
}
@Test
public void test() {
System.out.println("Test " + s);
}
}
Upvotes: 1