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
0
votes
1 answer

Jacoco doesn't include the Robolectic Test coverage

On my android project jacoco doesn't include the robolectic tests. I can get the android espresso and junit test coverage with jacoco without any issues. I did see other questions about this issue and all the answers is to upgrade jacoco version.…
Libin
  • 16,967
  • 7
  • 61
  • 83
0
votes
0 answers

Exception while running Robolectric for vector drawable

I'm trying to run Robolectric test. I'm getting the following error once I run the test android.content.res.Resources$NotFoundException: Resource ID #0x7f020052 at android.content.res.Resources.getValue(Resources.java:1013) at…
Vikas B L
  • 397
  • 1
  • 10
0
votes
1 answer

How to test method that uses system service using Robolectric?

public class SomeClass { public void someMethod() { final TelephonyManager telephonyManager = (TelephonyManager) getContext().getSystemService(Context.TELEPHONY_SERVICE); ..... more code } } I need to…
apatel
  • 21
  • 4
0
votes
2 answers

Robolectric PowerMock java.lang.NoClassDefFoundError error while running a test

I want to integrate powermock to test firebase logic. I tried to run a test and got this: java.lang.NoClassDefFoundError: org/mockito/cglib/proxy/MethodInterceptor Here is my app.gradle: testCompile 'junit:junit:4.12' testCompile…
Semyon Tikhonenko
  • 3,872
  • 6
  • 36
  • 61
0
votes
0 answers

Unit Tetsing android Service Layer (Retrofit) using Robolectric and Mockito

I have developed a android application which integrated retrofit 2.0 Not i have added few service calls and wants write unit test for it , I've decided to use Robolectric since it separately run and i can run with CI integration and to mock objects…
Mr.G
  • 1,275
  • 1
  • 18
  • 48
0
votes
0 answers

Robolectric test compiling classes for each run

In my project, one robolectric(v3.1.2) test is taking 30 seconds to run when executed from Android Studio. When profiled, much of the time is spent on :app:compile*JavaWithJavac task. This task is executed even when no change is made to the code. Is…
0
votes
1 answer

AssertThat error: Cannot access path (java.nio.file.Path not found)

I want to use Robolectric for Unit Testing but I am trying a simple test with robolectric and I am stuck at the beginning. I followed the manual, I did the same with the examples and even other posts couldn't help me. Every time I get the error…
mischi
  • 25
  • 9
0
votes
1 answer

Android Studio / Robolectric tests fails randomly

I am using Android Studio 3.3 and I have some tests with Robolectric 3.3.2. I have multiple problems that may be connected. I start Android studio and run my test class. It is OK. If I modify / add a test, it is not seen when I rerun the tests…
Guillaume
  • 135
  • 1
  • 8
0
votes
1 answer

Robolectric fails to load properly when launching single test

I have an Android application that I test using @RunWith(RobolectricTestRunner.class). When I run all tests together in Android Studio, it works. But when I run a test or test class separately, I get this error:…
JM Lord
  • 1,031
  • 1
  • 13
  • 29
0
votes
1 answer

Are Firebase analytics events sent when running Robolectric tests?

I am using Firebase Analytics in my Android project. I am also using Robolectric for tests. When running Robolectric tests are Firebase events sent? During the tests the code does reach FirebaseAnalytics.getInstance(context).logEvent(eventName,…
Kaarel Purde
  • 409
  • 1
  • 5
  • 12
0
votes
1 answer

Mocking only specific code line inside whole method

I have code where I want to test a method, but to mock only a specific part inside that method, for instance, I want to call to doNetworkWork and do it completely and only return specific behavior on the call to: mRestPR.callNetwork(restCall) so if…
RonTr
  • 137
  • 10
0
votes
1 answer

NullPointerException in super class method's constructor when testing using mockito

I have a super class: public class A extends Fragment{ public A(Context context){ super(context); } } and class B inherits it: public class B extends A{ public B(Context context){ super(context); } } In my test…
syfy
  • 607
  • 3
  • 12
  • 19
0
votes
1 answer

Robolectric 3.3.2 Facebook 4.3 and above compatability issues

I have issues running my unit tests with a specific version of Robolectric and Facebook. My test scripts work when I have the following testCompile "org.robolectric:robolectric:3.3.2" testCompile "org.robolectric:shadows-multidex:3.3.2" testCompile…
Killesk
  • 2,734
  • 3
  • 22
  • 29
0
votes
0 answers

Robolectric and Mockito testing for Android FSM app

I wrote a simple Android FSM app like described here. And I need to test it with Robolectric and Mockito in Android Studio. I've installed these plugins and read all the documentation, but have no idea how to test if() method using these…
ukroid
  • 1
  • 2
0
votes
1 answer

Robolectric can not run test with enabled multidex

I am writing unit tests to cover API with tests. I use robolectric and gradle, also have to add multidex to support large apk build. Unexpectedly I can not run the test and can not understand the stacktrace java.lang.NullPointerException:…
Gleichmut
  • 5,953
  • 5
  • 24
  • 32
1 2 3
99
100