1 min read

Troubles when trying to mock the Bundle class with Mockito

Yesterday I got this issue while trying to test some code that contained a Bundle object within.

When I tried to mock the Bundle class... Nothing was happening and the test was constantly failing with:

java.lang.RuntimeException: Method putString in android.os.BaseBundle not mocked.


The only solution I found that worked out was to add this to the app's build.gradle:

android {
    testOptions {
        unitTests.returnDefaultValues = true

I hope that I saved you some time! :)