简体   繁体   中英

Using Power Mock for Unit testing in Android Framework

I have been trying to Unit test in Android using PowerMock and Mockito. I am successful in mocking through Mockito, but since Mockito cannot mock Static methods and final classes , So I need to include PowerMock along with Mockito.

But whenever I use the line

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

It is giving 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

This blog post shows that you cannot merely include mockito into an android test project. http://www.paulbutcher.com/2012/05/mockito-on-android-step-by-step/

If you must use mocking frameworks, either follow steps in that or use something like the robolectric framework.

您是否将@PrepareForTest(Example.class)注释添加到测试类的顶部?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM