Gauge - run @BeforeSpec in a superclass in Java

263 Views Asked by At

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?

1

There are 1 best solutions below

0
On

Try to use a static variable:

public class A {
   public static String property = "";
   @BeforeSpec
   public void init(){
      property = "hello";
   }
}

public class B {
   @Step("...")
   public void verifyProperty() {
       assertEquals(A.property, "hello");
   }
}