testng
testng copied to clipboard
@BeforeMethod in super classes depends on method visibility
See post on the user's group: https://groups.google.com/forum/#!topic/testng-users/fJd90c1RPWM
With a little bit of ad-hoc testing, it seems that if a superclass has a @BeforeMethod annotation, the sub-test-class only run it first (or even at all?) if it has protected visibility
import java.util.*;
import static org.testng.Assert.*;
import org.testng.annotations.*;
class SuperSampleTest {
List<String> order = new ArrayList<>(2);
@BeforeMethod
public void superSetup() {
System.out.println("running super");
order.add("super");
}
}
public class SampleTest extends SuperSampleTest {
@BeforeMethod
public void childSetup() {
System.out.println("running child");
order.add("child");
}
@Test
public void verifyOrder() {
if (order.get(0).equals("child"))
fail("child before method ran before super!");
}
}
I try to run it in my side and both super and child are run, the order is super and child