Arthur Zagretdinov edited this page Jun 15, 2017 · 4 revisions

Using @PowerMockRunnerDelegate

   Feature avaliable since PowerMock 1.6.0

Since version 1.6.0 PowerMock has support for delegating the test execution to another JUnit runner without using a JUnit Rule. This leaves the actual test-execution to another runner of your choice. For example tests can delegate to "SpringJUnit4ClassRunner", "Parameterized" or the "Enclosed" runner. Usage example:

@PrepareForTest({FinalDemo.class, PrivateFinal.class})
public class FinalDemoTest {

    public String expected;

    @Parameterized.Parameters(name = "expected={0}")
    public static Collection<?> expections() {
        return java.util.Arrays.asList(new Object[][]{
            {"Hello altered World"}, {"something"}, {"test"}

    public void assertMockFinalWithExpectationsWorks() throws Exception {
        final String argument = "hello";

        FinalDemo tested = mock(FinalDemo.class);


        final String actual = "" + tested.say(argument);


        assertEquals("Expected and actual did not match", expected, actual);