Questions tagged [robolectric]

1

votes
1

answer
48

Views

AndroidThreeTen not working in unit test without robolectric?

I'm having trouble creating a unit test without needing robolectric. I am using AndroidThreeTen.init(this) in my code and when I run my test if I disable robolectric I get an error: org.threeten.bp.zone.ZoneRulesException: No time-zone data files registered and if I leave it enabled I get this: [Ro...
Crash1hd
1

votes
1

answer
12

Views

How can test MutableLiveData<>.observe when the data is changed?

I have the next code for test if the API is working with Login function: @RunWith(RobolectricTestRunner.class) public class LoginTest { LoginRespository profileRepository = new LoginRespository(RuntimeEnvironment.application); @Test public void testLogin() { MutableLiveData data = new MutableLiveDat...
Tlaloc-ES
1

votes
0

answer
618

Views

lateinit property presenter has not been initialized with EasyMVP, Robolectric and Kotlin

I have problem while trying to use Robolectric to test activity which is using EasyMvp. All of the classes are written in Kotlin. This is beginning of an activity: @ActivityView(layout = R.layout.activity_access, presenter = AccessPresenterImpl::class) class AccessActivity : BaseActivity(), AccessVi...
Jakub Anioła
1

votes
1

answer
266

Views

Robolectric not handling getApplicationContext() correctly - NPE

I've been running some tests on an android application using Robolectric and it's been working well until now. My application passes the result of getApplicationContext() to a constructor, but Robolectric should be ensuring the value of this is not null as I am using the BuildActivity() method. The...
Andreas Lärfors
1

votes
0

answer
36

Views

Tealium && Robolectric

Problem with Tealium if we use robolectric all over. We have our UnitTest without calling methods from Tealium successfully. However, there're crash at all tests if we use it. We have ShadowApplication in tests. java.lang.VerifyError: Expecting a stackmap frame at branch target 50 Exception Detail...
TeeTracker
1

votes
0

answer
121

Views

Unit Testing - Inner class receives null when accessing outer class fields

I'm writing unit tests for a class with an inner class. When I try to access variables belonging to the outer class from inside the inner class, they resolve to be null. However, this is only when running the unit tests. class Outer { private final SomeClass foo; Outer(SomeClass foo) { this.foo = fo...
Alex Meuer
1

votes
1

answer
46

Views

How to Signup a ParseUser in Local Unit Test

In Local unit test, does VM allow to hit online through ParseUser, and Signup?
Awais Ali
1

votes
0

answer
106

Views

Robolectric: interaction with dialog, created anonymously on view click

I am new to robolectric as well as to testing android.* classes, and here is a problem: when user wants to specify his birthday, he clicks on a textview, which invokes a DatePickerDialog, and specified date is meant to be shown in the textview. Here is no any external links to the dialog. My code: i...
Andrey Ilyunin
1

votes
0

answer
59

Views

How parcel.writeString(null) supposed to work on API18?

The parcel.writeString(null); does not persist anything or at least it is not readable. Running the code below will cause the exception below. The test has no problem running on a real device or on an emulator. However if I am running the test in a headless environment using API18 I am having this i...
Istvan
1

votes
0

answer
157

Views

Firebase Auth test using Roboelectric keeps failing

When running this test I get null pointer exception. I checked if everything is fine with the button. So there is a problem with either roboelectric or firebase. I've got no idea why it is happening. Everything is working fine when I do this by hand. User is created and activity changes. Edit: UI te...
dawzaw
1

votes
0

answer
41

Views

Application using segment analytics throwing java.lang.IllegalArgumentException: INTERNET permission is required

Problem : I am trying to run test cases for my app using robolectric. My application is segment analytics. Its throwing Internet permission exception while its already there in my manifest file. robolectric version : 3.7.1, targetSDKVersion : 26, gradle : 3.0.1 command : ./gradlew clean testBuildDe...
Sunil Kumar
1

votes
0

answer
86

Views

NotificationManager.isNotificationPolicyAccessGranted NPE in Robolectric

I have want to write a simple test involving Robolectric's notificationManager.isNotificationPolicyAccessGranted. package com.xi_zz.mutephonebutton import android.app.NotificationManager import android.app.NotificationManager.INTERRUPTION_FILTER_ALL import android.app.NotificationManager.INTERRUPTIO...
Xi Wei
1

votes
0

answer
298

Views

The SourceSet 'robolectric' is not recognized by the Android Gradle Plugin

Updated to Android Studio 3.1 and its corresponding gradle. I'm getting a message when trying to sync 'The SourceSet 'robolectric' is not recognized by the Android Gradle Plugin. Perhaps you misspelled something?'. Here is the current sourceSet in the gradle file: sourceSets { main { java.srcDirs =...
Axel
1

votes
0

answer
29

Views

How to test whether the activity has not been routed with Robolectric?

I have an activity which is as simple as this: class HomeActivity : BaseActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_home) if (!this.userPreference.memberRegistered) { goToActivity(AuthActivity::class.java) } }...
Albert Gao
1

votes
0

answer
183

Views

Android paging library test with Robolectric?

Hy ! :) Someone has any idea how can i test Paging Library by Google implementation with recyclerview ? My implementation is same to: Example Pagig lib impl.
Dancs Berci
1

votes
0

answer
46

Views

Testing PopUpMenu with Robolectric

I have an Image on click of which I display a PopUpMenu. I am not getting any way to test that particular pop up menu that is being displayed. I have two buttons 1) Edit , 2) Delete and what I want to test is the click of the Delete and the edit. Any help is welcome.
Gaurav A Dubey
1

votes
0

answer
149

Views

Illegal connection pointer running Robolectric tests with ContentResolver

I want to test a class that manages data and uses a custom ContentProvider, with Robolectric. I've made a test class with two tests that use a ShadowContentResolver to set some data in the ContentProvider. These tests work perfectly on their own, but if I test the whole class, I get an error in the...
dumazy
1

votes
0

answer
51

Views

How to test IntentService with Roboelectric - with an error

I'm having an error message below and looked around but there is a solution for service and tried to get it right. How to test an IntentService with Robolectric? java.lang.RuntimeException: java.lang.NoSuchMethodException: tapme.data.service.AlarmService.(java.lang.String) Here is the unit test tha...
Meep
1

votes
0

answer
141

Views

org.robolectric:shadows-supportv4 doesn't support Jetpack(androidx)

Main repo: org.robolectric:robolectric:4.0-alpha-4-SNAPSHOT works with androidx org.robolectric:shadows-supportv4 doesn't work, ie: class TestSupportFragment extends androidx.fragment.app.Fragment doesn't work -----> SupportFragmentController.of(new TestSupportFragment()) any snapshot for shadows-...
TeeTracker
1

votes
0

answer
81

Views

Testing BaseActivity

I have a BaseActivity, which has Dagger behavior inside: abstract class BaseActivity : DaggerAppCompatActivity(), HasSupportFragmentInjector { @Inject lateinit var fragmentDispatchingAndroidInjector: DispatchingAndroidInjector override fun onCreate(savedInstanceState: Bundle?, persistentState: Per...
BestPractice2Go
1

votes
1

answer
161

Views

RobolectricTestRunner class not found after SDK and Gradle upgrade

I upgraded recent legacy android application as follows, CompileSDK 23 to 27 BuildTools 23.0.2 to 27.0.3 SupportLibVersion 23.0.2 to 27.1.1 below is my previous and current sourceset and test options code sourceSets { main { assets.srcDirs = ['src/main/assets', 'src/main/assets/'] java.srcDirs = ['...
Learner_Programmer
1

votes
0

answer
131

Views

Android API 28 and Roboelectric 4.0-alpha-3 throwing Realm lib error

On switching the project to API 28 (compileSdk and targetSdk) Robolectric warned that it does not support API 28. On then updating the Robolectric dependency from v3.6.1 to: testImplementation 'org.robolectric:robolectric:4.0-alpha-3' Running tests then produces this error: java.lang.UnsatisfiedLink...
Ollie C
1

votes
1

answer
41

Views

Robolectric hanging in some instances with Android databinding

I've already raised an issue for Robolectric, but have had no response there, so perhaps SO can help me. We've a large app that uses Android Data Binding, and it currently on the rather old com.android.tools.build:gradle:2.1.3. We have Robolectric 3.8 tests that currently all work ok. We want to upg...
Jonathan Caryl
1

votes
1

answer
27

Views

upgraded to roboelectric 4.0 and it gives dependency error

upgraded to robolectric:4.0 and get error Module 'org.robolectric:robolectric:4.0' depends on one or more Android Libraries but is a jar
chuksleomc
1

votes
0

answer
99

Views

How can I unit test Android View animation endAction?

fun TextView.setTextWithFade(text: String, duration: Long = 300) { this.animate().alpha(0f).setDuration(duration).withEndAction { this.text = text this.animate().alpha(1f).setDuration(duration).start() }.start() } Hello, I have a simple Kotlin extension function for a TextView to change text with an...
Arnas Smičius
1

votes
1

answer
113

Views

How to test androidx.fragment.app.Fragment.onCreateOptionsMenu()?

I'm having trouble converting some of my old Robolectric 3.x tests to the new style (also converted to AndroidX at the same time). My setup: - Android Gradle Plugin 3.2.1 - Robolectric 4.1 Some relevant config (gradle.properties): android.useAndroidX=true android.enableJetifier=false Note, I am not...
Alix
1

votes
1

answer
63

Views

How to connect android studio testing GUI to gradle task?

There are some tests in my android project and configured CI Before deploying tests are launched using gradle wrapper(4.10.3) 95% of tests are robolectric tests And there are cases when these tests are not passing because of different reasons, but the problem is that when i run them from android s...
Andrew Tomas
1

votes
2

answer
94

Views

How do I fix Null Pointer Exception when I have already assigned value [duplicate]

This question already has an answer here: What is a NullPointerException, and how do I fix it? 12 answers I am writing unit testing for a function using roboelectric and facing null pointer exception but I have already assigned the variable. I'm pretty new to this so if any mistake please pardon me...
anirudh
1

votes
0

answer
24

Views

Robolectric and AndroidX ClassNotFoundException android.support.v4.app.NotificationCompat$Style

I am trying to use Robolectric in order to unit test some classes in an Android application without using an emulator or a device. I would like, for example, to unit test a Dao class but I always have the following exception : Caused by: java.lang.ClassNotFoundException: android.support.v4.app.Notif...
rolandl
1

votes
1

answer
916

Views

Robolectric Issue with ProgressBar

I keep getting a RuntimeException from Robolectric when it tries to invoke an onCreate for an activity that has a ProgressBar. I've localized the issue to this block in the layout xml file. As soon as I remove this and re-run the test, things work fine. Here is the full stack trace: java.lang.Runtim...
Ali
0

votes
0

answer
5

Views

robolectric throws FragmentManager is already executing transactions

I run a specific unit-test: @Rule public ActivityScenarioRule activityScenarioRule2 = new ActivityScenarioRule(FragmentUtilActivity.class); @Before public void setUp() { ... //not related to activityScenarioRule2 } @Test @Config(qualifiers = 'sw600dp') public void myTest() { activityScenarioRule2 .g...
Elad Benda
1

votes
1

answer
127

Views

What is the meaning of “ant maven-setup” in Roboelectic Maven Build?

I am trying to use RobolectricSample application for unit testing Android application. In the instruction for installation of application with Maven the first step is ant maven-setup. I could not understand why is this command required and what it will do? Any explanation will be great help.
Gaurav Agarwal
1

votes
1

answer
332

Views

How to add WidgetProvider without breaking Robolectric

I have a testsuite using Robolectric 1.1 and Roboguice 2. It runs fine. I added an AppWidget to the application manifest as: I've created a class public class NearestOpenCragWidgetProvider extends AppWidgetProvider { public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] app...
Paul D'Ambra
1

votes
2

answer
595

Views

Assert context menu using Robolectric

The situation is the following: I have a ListView and when long click is performed on an item a context menu is shown. I've checked it on the emulator but now I want to assert that the context menu appears. Is there a way to assert that a context menu has been shown using Robolectric?
Alfergon
1

votes
1

answer
392

Views

Can I use Robolectric to unit test static library jars?

I'm trying to test a method in a jar library, and was hoping to use Robolectric to do my unit testing, rather than running the tests in the Android emulator. I'm running into a problem though, where Robolectric needs an androidmanifest.xml file that doesn't exist, since I'm building a library... Is...
Greg
1

votes
1

answer
139

Views

Robolectric simple test

I was trying to test a very simple calculator app with Robolectric. @Before public void setUp(){ mActivity = new MainActivity(); mActivity.onCreate(new Bundle()); et1 = (EditText) mActivity.findViewById(com.mamlambo.article.simplecalc.R.id.value1); et2 = (EditText) mActivity.findViewById(com.mamlam...
Traxex1909
1

votes
3

answer
1.9k

Views

RobolectricTestRunner, Test class can only have one constructor

So I have this error, using Robolectric. java.lang.IllegalArgumentException: Test class can only have one constructor at org.junit.runners.model.TestClass.(TestClass.java:40) at org.junit.runners.ParentRunner.(ParentRunner.java:75) at org.junit.runners.BlockJUnit4ClassRunner.(BlockJUnit4ClassRunner....
jakk
1

votes
1

answer
750

Views

Where does Robolectic on Android, save files created during test runs?

I want to ensure a byte array is being converted to a jpg correctly. I've simplified the problem as follows: public String saveToFile(String filename, String contents) { String storageState = Environment.getExternalStorageState(); if(!storageState.equals(Environment.MEDIA_MOUNTED)) { throw new Illeg...
Ed_
1

votes
1

answer
1.4k

Views

Robolectric test run InflateException for android.support.v4.widget.DrawerLayout

I'm using Robolectric head and am targeting Android 14 and have it and am using Android 18 to compile the module. You can see the commented LinearLayout which works under test below. I'm attempting to inflate the following. I have the v4 support jar marked as 'compile' in IntelliJ. Not sure what els...
gleenn
1

votes
2

answer
837

Views

Can't capture HTTP request with robolectric

I am trying to capture an http request with Robolectric The method tokenize method sends a request to a server and I just want to test that the post is sent: If I try //Cardtest.java Robolectric.setDefaultHttpResponse(200, 'dummy'); card.tokenize(paymentHandler); Robolectric.getSentHttpRequest(0);...
Elie

View additional questions