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:
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
- Prefer non-synthetic constructors in MockMethodAdvice.ConstructorShortcut After moving spy creation to instrumenting constructor chains in ByteBuddyMockMaker, creating spies for Robolectric-instrumen... — committed to hoisie/mockito by hoisie 4 years ago
- Prefer non-synthetic constructors in MockMethodAdvice.ConstructorShortcut After moving spy creation to instrumenting constructor chains in ByteBuddyMockMaker, creating spies for Robolectric-instrumen... — committed to hoisie/mockito by hoisie 4 years ago
- Prefer non-synthetic constructors in MockMethodAdvice.ConstructorShortcut After moving spy creation to instrumenting constructor chains in ByteBuddyMockMaker, creating spies for Robolectric-instrumen... — committed to hoisie/mockito by hoisie 4 years ago
- Do not exclude synthetic constructors from instrumentation. Fixes #2040. — committed to mockito/mockito by raphw 4 years ago
- [ci maven-central-release] Merge pull request #2046 from mockito/include-synthetic Do not exclude synthetic constructors from instrumentation. Fixes #2040. — committed to mockito/mockito by raphw 4 years ago
Thanks for all your hard work @raphw! I am glad this is fixed.