0

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() {

    }
}
Semyon Tikhonenko
  • 3,872
  • 6
  • 36
  • 61
  • 1
    Can you use the latest version of mockito supported by powermock? For example `testCompile 'org.mockito:mockito-core:2.8.9'` – David Rawson Sep 06 '17 at 22:18
  • Also, wrapping the `final` Firebase classes in your own non-final interfaces is a better solution than using Powermock – David Rawson Sep 06 '17 at 22:21

2 Answers2

2

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.

Artur Zagretdinov
  • 2,034
  • 13
  • 22
1

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.

GhostCat
  • 137,827
  • 25
  • 176
  • 248