unit testing - PowerMock on Android Project -
hello powermock users,
i trying write android testcases using powermockito. using eclipse ide , run tests "android junit tests"
when mockito v1.9.5 (along dexmaker-1.1.jar & dexmaker-mockito-1.1.jar) test pass. of test have mocks , don't.
when add powermock-mockito-1.5.6-full.jar libs folder , change imports
import static org.powermock.api.mockito.powermockito.*;
things start break. ( using mock() , when() calls )
below testcase class:
@runwith(powermockrunner.class) @preparefortest({authsettings.class}) public class networkservicesimpltest extends activitytestcase{ @override protected void setup() throws exception { super.setup(); system.setproperty("dexmaker.dexcache", getinstrumentation().gettargetcontext().getcachedir().getpath()); thread.currentthread().setcontextclassloader(getclass().getclassloader()); obj = new myobj(); } private myobject obj; public void testsimpletest() { response response = mock(response.class); data data = mock(data.class); when(response.getstring()).thenreturn("dummy"); obj.setstring(response); string str1 = obj.getstring(dscontext, data); assertequals("dummy",str1); } public void testgetdsclientexecutioncontexturl() throws malformedurlexception { dshttpresponse response; // mock our class httprequestparameters mockhttprequest = mock(httprequestparameters.class); final url url = new url("https://"); try{ // powermock api whennew(httprequestparameters.class).withnoarguments().thenreturn(mockhttprequest); response = network.get(dscontext, url); }catch(exception ex){ response = null; fail("should not have got exception" + ex); } assertnotnull(response); }
this exception on first testcase:
java.lang.verifyerror: org/mockito/cglib/core/reflectutils @ org.mockito.cglib.core.keyfactory$generator.generateclass(keyfactory.java:167) @ org.mockito.cglib.core.defaultgeneratorstrategy.generate(defaultgeneratorstrategy.java:25) @ org.mockito.cglib.core.abstractclassgenerator.create(abstractclassgenerator.java:217) @ org.mockito.cglib.core.keyfactory$generator.create(keyfactory.java:145) @ org.mockito.cglib.core.keyfactory.create(keyfactory.java:117) @ org.mockito.cglib.core.keyfactory.create(keyfactory.java:109) @ org.mockito.cglib.core.keyfactory.create(keyfactory.java:105) @ org.mockito.cglib.proxy.enhancer.<clinit>(enhancer.java:70) @ org.mockito.internal.creation.jmock.classimposterizer.createproxyclass(classimposterizer.java:85) @ org.mockito.internal.creation.jmock.classimposterizer.imposterise(classimposterizer.java:62) @ org.powermock.api.mockito.internal.mockcreation.mockcreator.createmethodinvocationcontrol(mockcreator.java:111) @ org.powermock.api.mockito.internal.mockcreation.mockcreator.mock(mockcreator.java:60) @ org.powermock.api.mockito.powermockito.mock(powermockito.java:143) @ com.citrix.work.network.impl.test.networkservicesimpltest.testsimpletest(networkservicesimpltest.java:91) @ java.lang.reflect.method.invokenative(native method) @ android.test.instrumentationtestcase.runmethod(instrumentationtestcase.java:214) @ android.test.instrumentationtestcase.runtest(instrumentationtestcase.java:199) @ android.test.androidtestrunner.runtest(androidtestrunner.java:191) @ android.test.androidtestrunner.runtest(androidtestrunner.java:176) @ android.test.instrumentationtestrunner.onstart(instrumentationtestrunner.java:554) @ android.app.instrumentation$instrumentationthread.run(instrumentation.java:1729)
and subsequest testcase throws
java.lang.noclassdeffounderror: org/mockito/internal/creation/jmock/classimposterizer$3 @ org.mockito.internal.creation.jmock.classimposterizer.createproxyclass(classimposterizer.java:85) @ org.mockito.internal.creation.jmock.classimposterizer.imposterise(classimposterizer.java:62) @ org.powermock.api.mockito.internal.mockcreation.mockcreator.createmethodinvocationcontrol(mockcreator.java:111) @ org.powermock.api.mockito.internal.mockcreation.mockcreator.mock(mockcreator.java:60) @ org.powermock.api.mockito.powermockito.mock(powermockito.java:143) @ com.citrix.work.network.impl.test.networkservicesimpltest.testgetdsclientexecutioncontexturl(networkservicesimpltest.java:107) @ java.lang.reflect.method.invokenative(native method) @ android.test.instrumentationtestcase.runmethod(instrumentationtestcase.java:214) @ android.test.instrumentationtestcase.runtest(instrumentationtestcase.java:199) @ android.test.androidtestrunner.runtest(androidtestrunner.java:191) @ android.test.androidtestrunner.runtest(androidtestrunner.java:176) @ android.test.instrumentationtestrunner.onstart(instrumentationtestrunner.java:554) @ android.app.instrumentation$instrumentationthread.run(instrumentation.java:1729)
does here have done unit testing on android project using powermockito ?
but when ran them command line setting classpath, tests ran. ran test using junit4 via
java -cp . org.junit.runner.junitcore <testclass>
any highly appreciated.
Comments
Post a Comment