Semyon Tikhonenko
Semyon Tikhonenko

Reputation: 4262

Robolectric PowerMock java.lang.NoClassDefFoundError error while running a test

I want to integrate powermock to test firebase logic. I tried to run a test and got this: java.lang.NoClassDefFoundError: org/mockito/cglib/proxy/MethodInterceptor

Here is my app.gradle:

testCompile 'junit:junit:4.12'
    testCompile "org.powermock:powermock-module-junit4:1.7.0"
    testCompile "org.powermock:powermock-module-junit4-rule:1.7.0"
    testCompile "org.powermock:powermock-api-mockito:1.7.0"
    testCompile "org.powermock:powermock-classloading-xstream:1.7.0"
    testCompile "org.robolectric:robolectric:3.4.2"
    testCompile 'org.mockito:mockito-core:2.1.0'

Here is my test:

@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class)
@PowerMockIgnore({ "org.mockito.*", "org.robolectric.*", "android.*" })
@PrepareForTest({FirebaseAuth.class, FirebaseDatabase.class})
public class LoginTest {

    @Before
    public void setUp() {
        PowerMockito.mockStatic(FirebaseAuth.class);
        Mockito.when(FirebaseAuth.getInstance()).thenReturn(Mockito.mock(FirebaseAuth.class));
    }

    @Test
    public void test() {

    }
}

Upvotes: 0

Views: 674

Answers (2)

Artur Zagretdinov
Artur Zagretdinov

Reputation: 2064

You are using 'org.mockito:mockito-core:2.1.0' with "org.powermock:powermock-api-mockito:1.7.0".

To use PowerMock with Mockito 2 the "org.powermock:powermock-api-mockito2:1.7.0" should be used.

Upvotes: 2

GhostCat
GhostCat

Reputation: 140523

You need the cglib library in your class path.

My solution is to always download a "complete" powermock ZIP from here. Those ZIP files contain everything you need in order to get going with PowerMock.

Upvotes: 1

Related Questions