I am writing some test classes and extending from base test class. But the problem is even though I lock the isInited variable it runs once for each class. It should be run once and initialize it after that it should not be called again but it calls 3 times since I have 3 classes that extends from base class. Please see below.
Java 1.8 and TestNG
public class BaseTest(){
private static isInited;
@BeforeClass
public void init(){
synchronized (BaseTest.class) {
//here even though I lock and initialize the variable this code is still called once for each class. I do not understand why this happens?
if (!isInited) {
//do some init
isInited=true;
}
}
}
public class TestClass1 extends BaseTest{
@BeforeClass
public void setup(){
//setup somethings
}
//test methods
}
public class TestClass2 extends BaseTest{
@BeforeClass
public void setup(){
//setup somethings
}
//test methods
}
public class TestClass3 extends BaseTest{
@BeforeClass
public void setup(){
//setup somethings
}
//test methods
}
Aucun commentaire:
Enregistrer un commentaire