How to mock a void static method to throw exception with Powermock?

前端 未结 3 1748
我在风中等你
我在风中等你 2020-12-15 03:23

I am trying to use Powermock and Mockito to mock a void static method to throw exception as below. But I met a problem. Unless I make the two invocations of Adder.add() with

3条回答
  •  自闭症患者
    2020-12-15 04:00

    Did you forget to put PowerMock in replay mode?

    How to Mock Static methods.

    Per your link...

    How to verify behavior Verification of a static method is done in two steps. First call PowerMockito.verifyStatic() to start verifying behavior and the call the static method you want to verify. E.g.

     PowerMockito.verifyStatic();
     Static.firstStaticMethod(param);
    

    Important: You need to call verifyStatic() per method verification.

提交回复
热议问题