Powermock: Notifications are not supported when all test-instances are created first

307 views
Skip to first unread message

mabb...@gmail.com

unread,
Apr 24, 2017, 1:12:06 PM4/24/17
to PowerMock

When I try to execute the below simplified JUnit test, it succeeds but i am getting an error message: Notifications are not supported when all test-instances are created first!


@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(BlockJUnit4ClassRunner.class)
@PrepareForTest({ A.class })
public class TestA extends TestB {
    @Test
    public void test() throws Exception {
        assertEquals(true, true);
    }
}

public class TestB {}
public class A {}


When I remove the @PowerMockRunnerDelegate(BlockJUnit4ClassRunner.class), OR the extends TestB OR the @PrepareForTest({ A.class }), the message disappears. Even an emtpy @PrepareForTest({ }) makes the error message appear.


I found this post, but it is not the same problem, because I am not using an extended BlockJUnit4ClassRunner.


I am trying to understand why this error message appears.


I am using the latest version of Powermock (1.6.6) and JUnit 4.12 and running the test using java8.


Best Regards,

Zagretdinov Arthur

unread,
Apr 25, 2017, 2:29:04 AM4/25/17
to powe...@googlegroups.com
Hi, 

PowerMock extends jUnit events message and fire some additional event during test life circle. PowerMockTestListener could be used to listen all jUnit and additional PowerMock events. 

One of this event required that an instance per test is created. A jUnit runner usually creates an new instance of test class per each test method in class, but some of them could create only one instance of class for all tests. When @PowerMockRunnerDelegate is used then delegated runner responsible for creating test instance. 

If event "test start" is fired without “test created” then PowerMock detects that all test instances are created before tests are started and cannot fire its internal events and this message is printed to system.err. So, you have the same issue as it has been described in post. 

PowerMock has only one implementation PowerMockTestListener at current moment - AnnotationEnabler. This implementation is used for integration with EasyMock and Mockito and supporting annotation like ‘@TestSubject’, ‘@Mock’ and so on. As result, then you see this message in console it means that these features could not work properly. But for Mockito case it could be easier fixed with using MockitoAnnotation.init(this).

Very interesting that if you remove ‘extends TestB’ the message is disappeared. I’ll check this case and investigate why it happen.   
 

Best regrads,
Arthur Zagretdinov


--
You received this message because you are subscribed to the Google Groups "PowerMock" group.
To unsubscribe from this group and stop receiving emails from it, send an email to powermock+...@googlegroups.com.
To post to this group, send email to powe...@googlegroups.com.
Visit this group at https://groups.google.com/group/powermock.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages