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

后端 未结 4 632
不知归路
不知归路 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:15

    Actually, you have to prepare for test the class that makes the constructor call, not the class on which the constructor was called. See https://github.com/jayway/powermock/wiki/MockConstructor.

    In your case, you should use @PrepareForTest(DummyTarget.class)

提交回复
热议问题