Hi,
I tried to generate parameteric tests with JUnit 4.6. I don't know if this is an
expected behavior.
Test Code
@RunWith(Parameterized.class)
public class JUnit4Test {
private String name;
@BeforeClass
public static void setUpOnceBeforeClass() throws Exception {
System.out.println("Before Class");
}
@Before
public void setUp() throws Exception {
System.out.println("Before Method");
}
@After
public void tearDown() throws Exception {
System.out.println("After Method");
}
@AfterClass
public static void tearDownOnceAfterClass() throws Exception {
System.out.println("After Class");
}
@Test()
public void testOne() throws Exception {
System.out.println("One");
}
@Test
public void testTwo() throws Exception {
System.out.println("Two");
}
@Test
public void testThree() throws Exception {
System.out.println(this.name);
}
public JUnit4Test(String name) {
this.name = name;
}
@Parameters
public static Collection<Object[]> getNames() {
return Arrays.asList(new Object[][] {
{"Kartik"}, {"Rakesh"}, {"Ed"}
});
}
}
My output
Before Class
Before Method
One
After Method
Before Method
Two
After Method
Before Method
Kartik
After Method
Before Method
One
After Method
Before Method
Two
After Method
Before Method
Rakesh
After Method
Before Method
One
After Method
Before Method
Two
After Method
Before Method
Ed
After Method
After Class
It runs the unit tests three times. The testOne, testTwo outputs remain
unchanged, the testThree output changes with the depending upon the name.
Is this the expected behavior? I expected that testThree would run three times
each with a different parameter. Does anyone know if there is a reason for this
implementation.