Setting up Powemockito for static mocking

前端 未结 3 1002
感情败类
感情败类 2021-02-08 13:29

I would like to make use of Powermock with Mockito to mock some static method calls. I have followed instructions and examples from SO as well as the PowerMock Getting Started

3条回答
  •  你的背包
    2021-02-08 13:53

    Make sure powermockito and mockito versions aligned as in this chart - https://github.com/powermock/powermock/wiki/Mockito#supported-versions,

    Easy way to find is,

    mvn dependency:tree | grep mockito
    [INFO] |  \- org.mockito:mockito-core:jar:1.8.5:compile
    [INFO] +- org.mockito:mockito-all:jar:1.9.5:compile
    [INFO] +- org.powermock:powermock-api-mockito:jar:1.5.6:compile
    

    In my case, powermock 1.5.6 and mockito 1.9.5 were aligned but had to change to use mockito 1.8.5, as someone else in the dependency was already using mockito 1.8.5.

    Following combination perfectly works for me,

    mvn dependency:tree | grep mockito
    [INFO] |  \- org.mockito:mockito-core:jar:1.8.5:compile
    [INFO] +- org.mockito:mockito-all:jar:1.8.5:compile
    [INFO] +- org.powermock:powermock-api-mockito:jar:1.4.9:compile
    

提交回复
热议问题