question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:38 (16 by maintainers)

github_iconTop GitHub Comments

1reaction
hoisiecommented, Sep 17, 2020

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

0reactions
raphwcommented, Sep 18, 2020

Right back at you! Thanks for your patient debugging help!

Read more comments on GitHub >

github_iconTop Results From Across the Web

[GitHub] [fineract] renovate-bot opened a new pull request #1334 ...
[(#​2046)](https://togithub.com/mockito/mockito/pull/2046) - Mockito.spy(Activity).getBaseContext() returns null on Robolectric 4.4 and Java8 ...
Read more >
Bump 小米核从1.9.5到3.5.15:Bump mockito-core from ... - 编程技术网
[(#2046)](mockito/mockito#2046) Mockito.spy(Activity).getBaseContext() returns null on Robolectric 4.4 and Java8 [(#2040)](mockito/mockito#2040). За。5.10。
Read more >
[FIXED] Create file with Unit Test with Android in the emulator ...
@Test public void testGenerateFile() throws IOException { Context context ... This is a folder generated for robolectric instrumented test.
Read more >
Bump mockito-junit-jupiter from 3.5.9 to 3.6.0 - developer blog
Superseded by #105. Project: java-handbook. About this topic(Bump mockito-junit-jupiter from 3.5.9 to 3.6 ...
Read more >
Android client for Travis CI - AndroidRepo
brave-warrior/TravisClient-Android, Project description This project is unofficial Android client for Travis CI. It uses API v2 from Travis ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found