How can I mock private static method with PowerMockito?

后端 未结 3 1441
渐次进展
渐次进展 2020-12-08 15:07

I\'m trying to mock private static method anotherMethod(). See code below

public class Util {
    public static String method(){
        return          


        
3条回答
  •  南笙
    南笙 (楼主)
    2020-12-08 15:56

    I'm not sure what version of PowerMock you are using, but with the later version, you should be using @RunWith(PowerMockRunner.class) @PrepareForTest(Util.class)

    Saying this, I find using PowerMock to be really problematic and a sure sign of a poor design. If you have the time/opportunity to change the design, I would try and do that first.

提交回复
热议问题