I am writing a testing framework using Gauge. I want some initilization logic performed in one class, and the steps logic to reuse it, like this:
public class A {
protected String property = "";
@BeforeSpec
public void init(){
property = "hello";
}
}
public class B extends A {
@Step("...")
public void verifyProperty() {
assertEquals(property, "hello");
}
}
I can't seem to be able to achieve this. When performing the steps, the "property" is always null. Placing the @BeforeSpec in class B and calling super.init() works, but I would like to avoid having this call in every test class that extends A. Has anyone encountered and solved such an issue?
Try to use a static variable: