Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lsuski opened this issue Oct 19, 2018 · 7 comments
Open

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

lsuski opened this issue Oct 19, 2018 · 7 comments

Comments

@lsuski
Copy link

lsuski commented Oct 19, 2018

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?

@moltmann
Copy link
Contributor

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.

@lsuski
Copy link
Author

lsuski commented Oct 19, 2018

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

@moltmann
Copy link
Contributor

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?

@lsuski
Copy link
Author

lsuski commented Oct 19, 2018

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
Copy link
Author

lsuski commented Oct 22, 2018

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.

@moltmann
Copy link
Contributor

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.

@lsuski
Copy link
Author

lsuski commented Oct 23, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants