PowerMock: mocking of static methods (+ return original values in some particular methods)

前端 未结 4 2083
萌比男神i
萌比男神i 2020-12-05 15:23

I use PowerMock 1.4.7 and JUnit 4.8.2

I need to mock only some static methods and I want others (from the same class) just to return original value. When I mock with

4条回答
  •  囚心锁ツ
    2020-12-05 15:57

    You can also use the stubbing API:

    stub(method(MyStaticClass.class, "getB")).toReturn("B");
    

    Edit:

    To use stub and method statically import methods from these packages:

    1. org.powermock.api.support.membermodification.MemberModifier
    2. org.powermock.api.support.membermodification.MemberMatcher

    For more info refer to the documentation

提交回复
热议问题