Questions tagged [robolectric]

Robolectric is a unit testing framework that allows Android applications to be tested on the JVM in seconds without using an emulator or device.

Robolectric allows to run Android tests inside the JVM on your workstation. Running tests on an Android emulator or device is often slow. Building, deploying, and launching the app often takes a minute or more.

Robolectric is open sourced under MIT license.

Project website: robolectric.org

1684 questions
47
votes
7 answers

Testing that button starts an Activity with Robolectric

Hi I have the following code: @RunWith(Test9Runner.class) public class MainActivityTest { private MainActivity activity; private Button pressMeButton; @Before public void setUp() throws Exception { activity = new…
user739684
  • 473
  • 1
  • 4
  • 5
47
votes
2 answers

Android unit test case automation: Robolectric library vs Android Testing framework

Wondering which one is the better choice to write unit test cases for android apps and libraries: Using Robolectric library or sticking with Android Testing framework. I want to run test suite at commandline and want it be independent of need of…
bianca
  • 7,004
  • 12
  • 43
  • 58
45
votes
4 answers

Robolectric and Android SDK 29

When will Robolectric be compatible with Android SDK 29? Did I upgraded too early by changing targetSdkVersion and compileSdkVersion to 29? When I run my unit tests I get this huge stacktrace: java.lang.IllegalArgumentException: API level 29 is not…
Bencri
  • 1,173
  • 1
  • 7
  • 22
45
votes
9 answers

Robolectric says "AndroidManifest.xml not found"

While trying to get Robolectric RC3 to work in Android Studio, I get Caused by: java.lang.RuntimeException: build/intermediates/bundles/debug/AndroidManifest.xml not found or not a file; it should point to your project's AndroidManifest.xml at…
Christine
  • 5,617
  • 4
  • 38
  • 61
43
votes
5 answers

Robolectric - Package targetSdkVersion=30 > maxSdkVersion=29

Error: java.lang.IllegalArgumentException: failed to configure : Package targetSdkVersion=30 >…
Abhimanyu
  • 11,351
  • 7
  • 51
  • 121
43
votes
3 answers

Unit Test Cases with JUnit +(Robolectric or Mockito or both in Android)

This is first time I have to write unit test cases in Android. So I have searched lots of things. Robolectric framewordk - Runs on JVM Mockito Framwork - Mocking objects So I have some doubts in Robolectric & Mokito. Should I have to use…
Deepanker Chaudhary
  • 1,694
  • 3
  • 15
  • 35
42
votes
1 answer

Robolectric unit tests fail after Multidex

So I recently merged my robolectric 3.0 upgrade with our mainline, which had added multidex support to our application. Unfortunately, this had the unfortunate side effect of causing our tests to fail/not run - they'd simply stop after the first…
40
votes
2 answers

How to debug when running Robolectric tests in Android Studio?

I need to run debug while my tests execution in Android Studio + Robolectric. Each time I try to run them by selecting debug for the test task from Gradle tasks I get the error message: Error running package_name:app_name [test]: Unable to open…
Eugene
  • 59,186
  • 91
  • 226
  • 333
38
votes
1 answer

Robolectric RuntimeEnvironment.application is deprecated, where is ApplicationProvider.getApplicationContext()?

I switched to Robolectric 4.0 Beta 1 from 3.8 because I need compatibility with Android 9 (API 28). With this change, RuntimeEnvironment.application is now deprecated. The replacement is apparently to…
Charles Madere
  • 6,642
  • 5
  • 35
  • 34
37
votes
5 answers

How to run unit tests with Android Studio

I'm using Jake's Android unit tests plugin for gradle: https://github.com/JakeWharton/gradle-android-test-plugin My build.gradle looks like this: dependencies { // analytics compile('com.crittercism:crittercism-android:3.0.11') //…
Eugen Martynov
  • 19,888
  • 10
  • 61
  • 114
34
votes
6 answers

Simulating a click on a menu item in Robolectric

It's fairly simple to simulate a button click in Robolectric: Button someButton = (Button) findViewById(R.id.some_button); someButton.performClick(); However, I can't seem to figure out how to do the same thing with a menu item. I create a menu in…
futlib
  • 8,258
  • 13
  • 40
  • 55
31
votes
5 answers

AndroidHttpClient not found (when running Robolectric)

I've set up a very simple project to test the integration of Robolectric + Data Binding + Retrolambda. When I run the test suit, I get the following message: Error:(30, 30) Gradle: error: cannot access AndroidHttpClient class file for…
Technocrat
  • 381
  • 1
  • 3
  • 6
31
votes
2 answers

Robolectric with Gradle: Resources not found

I'm trying to run my Robolectric tests together with the new Gradle Android build system, but I'm stuck at accessing the resources of my main project. I split the build into two separate projects to avoid conflicts between the java and the android…
passy
  • 7,170
  • 5
  • 36
  • 38
30
votes
4 answers

Unable to locate a Java Runtime Android Studio Robolectric

I've added Robolectric to an Android project. I'm using Android Studio with Build Tools in 19.0.1. I can run the tests with: $./gradlew test Which execute fine. If I try: $ gradle installDebug It executes fine as well: $ ./gradlew…
fstephany
  • 2,254
  • 3
  • 25
  • 32
30
votes
3 answers

Mock class in class under test

How I can mock with Mockito other classes in my class which is under test? For example: MyClass.java class MyClass { public boolean performAnything() { AnythingPerformerClass clazz = new AnythingPerformerClass(); return…
NikedLab
  • 883
  • 4
  • 11
  • 31