Questions tagged [android-unit-testing]
61 questions
0
votes
0 answers
How to test the Fragment having SearchView using Robo Electric
I have written so many Roboelectric Test Case and everything is working fine, But the layout containing the SearchView the test case fails , I just altered the searchview to AutoCompleteTextView or TextView or Edittext then the test cases passes ,
I…

Amit Ranjan
- 11
- 2
0
votes
1 answer
How to write unit tests for paging library in android
I need to write unit tests for doing a paginated network request. First I implemented paging library logic to retrieve the data.
I created a data source class and a repository class to get data from the network request.
This is my data source…

Jona
- 263
- 1
- 5
- 18
0
votes
0 answers
How to write spec for time Zone in angular
Below ill share, my code for reference
getTimeZoneTime(val: string) {
const userTimeZoneTime = moment
.utc(val)
.utcOffset(this.currentTimeZone)
.local()
.format('YYYY-MM-DD HH:mm:ss A');
return userTimeZoneTime;
…

Manoj Kumar
- 25
- 7
0
votes
0 answers
Error while running espresso test cases more than 150 case failed with an error (Out Of Memory)
When we have more than 150–200 automation test cases written for our application which takes around 1 to 1.5 hours to run completely. There we can face an issue of OOM (Out Of Memory) error while running test cases.
Tried solution methods…
0
votes
0 answers
How to unit test function that references CookieManager?
The application in question has a logout function that among other things, performs a call to CookieManager.getInstance().removeAllCookies(null):
fun logout(...) {
…

Orbit
- 2,985
- 9
- 49
- 106
0
votes
0 answers
Android PowerMockito of TextUtils returns wrong result
I have updated to Android 31 and Android Studio Dolphin and now my tests are failing because of TextUtils.isEmpty() returns wrong result.
I have this method to mock TextUtils.isEmpty().
protected void mockTextUtilsIsEmpty() {
…

Zookey
- 2,637
- 13
- 46
- 80
0
votes
0 answers
Android Studio Dolphin with latest gradle not correcting mapping test dependencies
I upgraded to Android Studio to 2021.3.1 Patch 1 and all the build tools at the same time. The tests were running without fail so I worked out stuff for a few day, but when I went to add a new test, I noticed all of the dependencies to the project…

a54studio
- 965
- 11
- 11
0
votes
0 answers
How to test a livedata with multiple value in Robolectric
Im trying to make an integration test in my viewmodel, which a livedata has multiple value in it. At the beginning of a function, this livedata will have a value of Loading, and after the network call is finished, it will have a value of success or…

lelestacia
- 201
- 2
- 9
0
votes
1 answer
Android Mockito - Mocking a function return value
Amateur question, but I can't seem to find an answer...
I am writing unit tests using Mockito and I have a utils function (isOnline(context)) which checks if I am offline before making a network call.
I am not trying to test that function, so I want…

Alon
- 883
- 1
- 6
- 18
0
votes
0 answers
Testing Android Coroutines with Test Rule by Inheritance vs Delegation
I am writing some mess around code to try and test coroutines and flows in Android. Following a common pattern I wrote a coroutine rule for handling the dispatcher and setting the main thread:
class CoroutineScopeRule(
val dispatcher:…

nomadian
- 1
0
votes
1 answer
Unit testing with Flavor keeps failing and show 'The events were not received'
I set,
testOptions {
animationsDisabled = true
unitTests.all {
useJUnitPlatform()
}
}
And I am using Java Home for Gradle JDK.
The error is here:
Execution failed for task…

c-an
- 3,543
- 5
- 35
- 82
0
votes
1 answer
mockk, get error when using mockkstatic for stub static function
using io.mockk 1.11.0
having some class with @JvmStatic function
class LogUtil {
@JvmStatic
fun logData(jsonStr: String) {
val jsonObj = getDataJson(jsonStr)
if (jsonObj == null) {
Log.e("+++", "+++ wrong json")
…

lannyf
- 9,865
- 12
- 70
- 152
0
votes
1 answer
How to test getter, setter method of a LiveData Android?
I am using Hilt for DI in my project. I am trying write unit test cases for LiveData object, but it's not coming under coverage.
ViewModel
@HiltViewModel
class HealthDiagnosticsViewModel @Inject constructor(
private var networkHelper:…

Kunu
- 5,078
- 6
- 33
- 61
0
votes
1 answer
android, why after covert to kotlin the unit test fail
On android app, Having a java function
JSONObject addToJson(@NonNull JSONObject jsonObject, @NonNull String key, boolean value){
try {
jsonObject.put(key, value);
} catch (JSONException e) {
…

lannyf
- 9,865
- 12
- 70
- 152
0
votes
1 answer
Unit Test ViewModels and Helper/Manager classes
I have a question related to Unit testing in android.
The app is written in Kotlin, MVVM architecture, Dagger-Hilt, Room, etc…
I have written all the tests for Room DAOs, according to official docs. I have created fake repositories so I can test…

Daguna
- 141
- 8