dexmaker icon indicating copy to clipboard operation
dexmaker copied to clipboard

Is it possible to use dexmaker-mockito-inline on API <28?

Open lsuski opened this issue 7 years ago • 7 comments

Hi, I need dexmaker-mockito-inline to run tests on Android 9.0, but I still want to run tests on older apis. Currently I have this error: Caused by: java.io.IOException: Requires API level 28. API level is 23

Is there a way to run tests on different API without changing gradle dependencies which is not quite convenient?

lsuski avatar Oct 19 '18 09:10 lsuski

dexmaker-mockito-inline just does not work before API 28. There is no fall back or anything.

You have to use dexmaker-mockito but they you cannot stub final methods.

Some people though about extending dexmaker-mockito-inline with class loader tricks to work for most classes on older platforms, but this is not implemented yet.

moltmann avatar Oct 19 '18 15:10 moltmann

In my case the problem is with hidden api spying and mocking which does not work on Android P.

lsuski avatar Oct 19 '18 15:10 lsuski

Can you give an example what you are trying to do. Beside the test and simplified app code, can you also describe what device you are running on?

moltmann avatar Oct 19 '18 15:10 moltmann

I'm spying ApplicationPackageManager which is hidden. It works well on api <28 with dexmaker-mockito, on 28 it works with dexmaker-mockito-inline

lsuski avatar Oct 19 '18 16:10 lsuski

I think I could be possible to provide proxy MockMaker which initialize MockMakerMultiplexer or DexmakerMockMaker based on system api version - this would sove the problem with hidden api but of course not with final methods. However mocking final methods hisorically is not common to mockito.

lsuski avatar Oct 22 '18 07:10 lsuski

dexmaker-mockito in the latest version should be able to deal with hidden methods.

I need the test, the gradle file and the test log to debug the issue.

moltmann avatar Oct 22 '18 16:10 moltmann

Check this project https://github.com/lsuski/dexmaker-hidden-api-test and ExampleInstrumentedTest

lsuski avatar Oct 23 '18 07:10 lsuski