The @BeforeClass method of the parent class is not called

According to this @BeforeClass document, superclass methods will execute to those of the current class. But this does not happen in my case.

I am using junit 4.8.1.

Could you tell me what I am doing wrong?

My parent class is as follows:

public abstract class AbstractPromoterUnitTest extends TestCase {
    @BeforeClass
    public static void setUpOnce() {
        // Do something here.
    }
}

These are child elements:

@RunWith(JUnit4.class)
public abstract class NormalPromoterUnitTest extends AbstractPromoterUnitTest{
    @BeforeClass
    public static void setUpOnce() {
        // Do something here 2.
    }
}

NormalPromoterUnitTest.setUpOnce () is called. AbstractPromoterUnitTest.setUpOnce () is not.

+5
source share
1 answer

You are hiding the static method of an abstract class; call one of them something else.

+8
source

All Articles