1

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 Answers1

0

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");
   }
}
Camilo Silva
  • 8,283
  • 4
  • 41
  • 61