Search code examples
androidunit-testingkotlinmockitopowermock

How to use PowerMock with Mockito3.x?


I am trying to use PowerMock for the first time. Currently, my app is using Mockito 3.x. I tried to setup PowerMock with following test dependencies:

testImplementation 'org.powermock:powermock-api-mockito:1.6.6'
testImplementation 'org.powermock:powermock-module-junit4-rule-agent:2.0.0'
testImplementation 'org.powermock:powermock-module-junit4-rule:2.0.0'
testImplementation 'org.powermock:powermock-module-junit4:2.0.0'

But, this results in failing test cases with the following error:

java.lang.NoClassDefFoundError: org/mockito/MockitoAnnotations$Mock

After reading the PowerMock doc, it seems that PowerMockito is not compatible with Mockito 3.x. If this is not the case, please help me to set up the PowerMock with Mockito 3.x


Solution

  • According to #1049, mockito 3.x is now supported by Powermock.