Search code examples
javaandroidunit-testingmockitopowermockito

PowerMockito gives NoClassDefFoundError


I'm trying to set up a unit test with Mockito and PowerMockito, but it throws:

Exception in thread "main" java.lang.NoClassDefFoundError: org/mockito/exceptions/Reporter

whenever I try to run a test. These are my dependencies:

testCompile 'org.mockito:mockito-core:2.8.9'
testCompile 'org.powermock:powermock-api-mockito2:1.6.5'
testCompile 'org.powermock:powermock-module-junit4:1.7.4'

Does anyone know how to fix it?


Solution

  • It seems you are trying to use incompatible versions.

    According to this table, you need to use version 1.7.x of Powermock in order to be compatible with your Mockito version 2.8.9.