Suppose I defined two class BaseClass and DerivedClass below. The waitPeriod for base is 1 minutes, and the waitPeriod for derived is 5 minutes.
class BaseClass {
protected String getDatasetType() {
return "BaseClass";
}
@BeforeClass
public void initialize() {
//some initialize
}
@Test
public void waitPeriod() {
long a = 1000*300; //wait 5 minutes
if (getDatasetType().equals("BaseClass")) {
a = 1000*60; // wait 1 minutes
}
try {
Thread.sleep(a);
} catch (InterruptedException e) {
e.printStackTrace();
}
log.info("waitPeriod " + getDatasetType());
}
@Test(dependsOnMethods = {"waitPeriod"})
public void test() {
log.info("test " + getDatasetType());
}
}
public class DerivedClass extends BaseClass {
@Override
protected String getDatasetType() { return "DerivedClass"; }
}
If run both class in the TestNG, ideally once after 1 minutes, it would only trigger the BaseClass's "test" function, and after 5 minutes, it would trigger the DerivedClass's "test" function. But during my test run, it triggered both of the test function after 1 minute.