Search code examples
javamockitopowermockito

Alternative @RunWith for PowerMockRunner?


Currently I have the following for my test class:

@RunWith(Parameterized.class)
@RunWith(PowerMockRunner.class)

public class TestApp extends TestGroovy {

...

}

I use 'Parameterized' for multiple inputs in a string concatenation. This is typically a template I use for most of my test units. However, I now have the need to add a PowerMock'ed class to my test unit and have had to add the @RunWith(PowerMockRunner.class) line. I obviously can't have multiple @RunWiths so what is an alternative? The test itself is as follows:

@Test
public void testCheckedApproved() throws Exception{
    PowerMockito.mockStatic(TRDIUtils.class);
    PowerMockito.when(TRDIUtils.strToInteger(newValueIn)).thenReturn(0);

    evaluate();
    Mockito.verify(dsIn, Mockito.times(1)).setItemDate(1,"XX_APPROV_DATE",new DateTime());
    Mockito.verify(dsIn, Mockito.times(1)).setItemString(1,"XX_APPROV_USER", dl.getSession().getUserId());
}

Solution

  • As is already posted in the comments, use PowerMockRunnerDelegate works for me:

    @RunWith(PowerMockRunner.class)
    @PowerMockRunnerDelegate(Parameterized.class)
    

    Could you try it?