-1

When "not mocked" error occurs, error message referencign the following page:

http://g.co/androidstudio/not-mocked

But this page has redirect to somewhere else so I have no time to read about an error. On the redirected page, although, an error is not covered.

Dims
  • 47,675
  • 117
  • 331
  • 600

1 Answers1

1

It can help you: Unit testing on Android Studio: "not mocked" error

Text from your link(sorry, i can't set this post as a comment) :

Note that when running tests from Gradle, we will execute tests for every variant of your code (see here). This means that tests will end up executing at least twice (once with the release build of your code, once with the debug build of production code).

"Method ... not mocked."

The android.jar file that is used to run unit tests does not contain any actual code - that is provided by the Android system image on real devices. Instead, all methods throw exceptions (by default). This is to make sure your unit tests only test your code and do not depend on any particular behaviour of the Android platform (that you have not explicitly mocked e.g. using Mockito). If that proves problematic, you can add the snippet below to your build.gradle to change this behavior:

android {
  // ...
  testOptions { 
    unitTests.returnDefaultValues = true
  }
}

We are aware that the default behavior is problematic when using classes like Log or TextUtils and will evaluate possible solutions in future releases.

Community
  • 1
  • 1
Ridami
  • 391
  • 2
  • 6