expert
expert

Reputation: 30125

@BeforeClass method of parent class is not invoked

According to this document @BeforeClass methods of superclasses will be run before those the current class. But it doesn't happen in my case.

I'm using junit 4.8.1.

Could you please tell me what I'm doing incorrectly ?

My parent class looks like this:

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

It's child:

@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.

Upvotes: 5

Views: 1425

Answers (1)

Dave Newton
Dave Newton

Reputation: 160191

You're shadowing the abstract class's static method; name one of them something different.

Upvotes: 8

Related Questions