@BeforeClass and inheritance - order of execution

前端 未结 16 2064
梦如初夏
梦如初夏 2020-12-02 11:39

I have an abstract base class, which I use as a base for my unit tests (TestNG 5.10). In this class, I initialize the whole environment for my tests, setting up database map

16条回答
  •  爱一瞬间的悲伤
    2020-12-02 12:20

    How about having your @BeforeClass method call an empty specificBeforeClass() method that may or may not be overwritten by sub classes like so:

    public class AbstractTestClass {
      @BeforeClass
      public void generalBeforeClass() {
        // do stuff
        specificBeforeClass();
      }
    
      protected void specificBeforeClass() {}
    }
    
    public class SpecificTest {
      @Override
      protected void specificBeforeClass() {
        // Do specific stuff
      }
    
      // Tests
    }
    

提交回复
热议问题