I have a test case that looks like so:
public class MyTest {
private static TestObject obj;
@BeforeClass
public static void setUpBeforeClass() {
obj = new TestObject();
}
@Test
public void testOne() {
assertTrue(obj.hasFoo());
}
@Test
public void testTwo() {
assertEquals(42, obj.getBar());
}
// More tests here...
}
What I want to do now is running the whole test case with different instances of TestObject. So let’s say I have 10 different TestObject instances. Now I want to run testOne() testTwo() and so on 10 times (with every instance of TestObject I need).
How can I achieve this with JUnit4? Or is my design bad? Any ideas for a better one?
Use parameterized test: