Using Power Mock to Test Units in Android Framework

I am trying to use Unit test in Android using PowerMock and Mockito. I manage to mock Mockito, but since Mockito cannot mock static methods and final classes, so I need to enable PowerMock along with Mockito.

But whenever I use the line

Example ma=PowerMockito.mock(Example.class);

      

It gives an exception:

    java.lang.ExceptionInInitializerError
at org.mockito.internal.creation.jmock.ClassImposterizer.createProxyCla(ClassImposterizer.java:85)
at org.mockito.internal.creation.jmock.ClassImposterizer.imposterise(ClassImposterizer.java:62)
at org.powermock.api.mockito.internal.mockcreation.MockCreator.createMethodInvocationControl(MockCreator.java:110)

      

What am I doing wrong. Thanks in Advance

+3


source to share


2 answers


This blog post shows that you can't just include mockito in an Android testing project. http://www.paulbutcher.com/2012/05/mockito-on-android-step-by-step/



If you must use mocking frameworks, follow these steps, or use something like a robolectric framework.

0


source


Have you added the @PrepareForTest (Example.class) annotation to the top of your test class?



0


source







All Articles