Mocking Static Blocks in Java

后端 未结 10 1997
南方客
南方客 2021-01-30 11:00

My motto for Java is \"just because Java has static blocks, it doesn\'t mean that you should be using them.\" Jokes aside, there are a lot of tricks in Java that make testing a

10条回答
  •  梦毁少年i
    2021-01-30 11:13

    You can use PowerMock to execute the private method call like:

    ClassWithStaticInit staticInitClass = new ClassWithStaticInit()
    Whitebox.invokeMethod(staticInitClass, "staticInit");
    

提交回复
热议问题