How do I mock a static method that returns void with PowerMock?

前端 未结 4 1282
傲寒
傲寒 2020-12-02 09:41

I have a few static util methods in my project, some of them just pass or throw an exception. There are a lot of examples out there on how to mock a static method that has a

4条回答
  •  生来不讨喜
    2020-12-02 10:27

    In simpler terms, Imagine if you want mock below line:

    StaticClass.method();
    

    then you write below lines of code to mock:

    PowerMockito.mockStatic(StaticClass.class);
    PowerMockito.doNothing().when(StaticClass.class);
    StaticClass.method();
    

提交回复
热议问题