Search code examples
junitmockitojunit4powermockpowermockito

@RunWith(PowerMockRunner.class) is disallowed for this location


I am getting following error

The annotation @RunWith is disallowed for this location

I have following imports.

import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;

@RunWith(PowerMockRunner.class)
@PrepareForTest(QueryValidator.class)
@Test
public void testValidateIds2() { ... }

What is causing this and how can I get rid of this.


Solution

  • figured @RunWith(PowerMockRunner.class) is a class level annotation and needs to go on top of the class, not the method.