mockito: Mockito.spy(Activity).getBaseContext() returns null on Robolectric 4.4 and Java8

Description

Since robolectric 4.4, Mockito.spy(Activity).getBaseContext() returns null

Steps to Reproduce

$ git clone -b mockito_spy_robolectric_4_4 https://github.com/ganadist/VersionCodeDemo demo
$ cd demo

// switch to robolectric 4.3.1
$ git checkout HEAD~1
$ ./gradlew :app:testDevelopDebugUnitTest
BUILD SUCCESSFUL in 14s
28 actionable tasks: 28 executed

// switch to robolectric 4.4
$ git checkout mockito_spy_robolectric_4_4
$ ./gradlew :app:testDevelopDebugUnitTest
> Task :app:testDevelopDebugUnitTest FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:testDevelopDebugUnitTest'.

Failed unittest result : https://scans.gradle.com/s/wbmmbnzatcyai/tests/:app:testDevelopDebugUnitTest/com.example.myapplication.UnitTest1/test1#1

Robolectric & Android Version

  • Compile Sdk : 29
  • Target Sdk : 28
  • Robolectric : 4.4
  • Mockito : 3.5.10
  • Jvm : OpenJDK 8

Link to a public git repo demonstrating the problem:

https://github.com/ganadist/VersionCodeDemo/blob/mockito_spy_robolectric_4_4/app/src/test/java/com/example/myapplication/UnitTest1.java#L27-L38

This issue is copied from https://github.com/robolectric/robolectric/issues/5916

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 38 (16 by maintainers)

Commits related to this issue

Most upvoted comments

Thanks for all your hard work @raphw! I am glad this is fixed.