@BeforeClass and inheritance - order of execution

前端 未结 16 2060
梦如初夏
梦如初夏 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条回答
  •  萌比男神i
    2020-12-02 12:24

    edit: Answer below is for JUnit, but I will leave it here anyway, because it could be helpful.

    According to the JUnit api: "The @BeforeClass methods of superclasses will be run before those the current class."

    I tested this, and it seems to work for me.

    However, as @Odys mentions below, for JUnit you need to have the two methods named differently though as doing otherwise will result in only the subclass method being run because the parent will be shadowed.

提交回复
热议问题