powermock mocking constructor via whennew() does not work with anonymous class

后端 未结 4 651
不知归路
不知归路 2021-01-03 20:34

I have a DummyResource class and a DummyTarget file, and a test class TestDummyResource as below, but the mocked object DummyResource dr = mock(DummyResource.class)

4条回答
  •  遥遥无期
    2021-01-03 21:27

    You need to have prepared the class calling the constructor, not the class on which the constructor is called, the following should fix you up:

    @PrepareForTest(DummyTarget.class)
    

    For more information check this page.

提交回复
热议问题