@BeforeClass and inheritance - order of execution

前端 未结 16 2089
梦如初夏
梦如初夏 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:21

    A better and cleaner way to achieve this using inheritance may be as following -

    abstract class A {
    
        @BeforeClass
        void doInitialization() {}
    }
    
    class B extends A {
    
        @Override
        @BeforeClass
        void doInitialization() {
            super.doInitialization();
        }
    
        @Test
        void doTests() {}
    }
    

提交回复
热议问题