54 questions
2
votes
1
answer
164
views
How do I run unit tests for single flavor without running all tests?
I'm working on unit tests for my Android app. My app has two flavors: "flavor 1" and "flavor 2", configured in default.gradle. Tests common to both are in test and I also have ...
0
votes
0
answers
172
views
Exclude hilt generated classes from android unit test coverage report
When generating coverage report in Android unit test by selection option "Run **test with coverage", we see a lot of hilt generated classes being added to the report giving us wrong coverage ...
0
votes
1
answer
209
views
Why ViewModel's StateFlow is not updating when inside a unit test and is mapped from a repository to UI state using stateIn?
I am testing a ViewModel using a fake repository which uses a StateFlow to store the fake data. This StateFlow is exposed as a normal Flow from the repository. In the ViewModel, I am mapping the ...
0
votes
1
answer
139
views
How to write Unit Test Case for singleton class kotlin
I want to release current instance but that not working here is there any easier way to handle it.
I have a class -> DownloadManager which is singleton
And I have a @Before test which always ...
1
vote
1
answer
614
views
Accessing a res/raw file from Unit tests
In my Android project, I have a file in res/raw/config.json. In Android application, this file can be accessed via resources.openRawResource().
Is there a way, how to access this file from Unit tests (...
1
vote
0
answers
96
views
Unit testing for pending intent
Any idea on how to write unit test case for the below function:
PendingIntent pendingIntent = new NavDeepLinkBuilder(context)
.setGraph(R.navigation.flow_nav_graph)
....
-1
votes
1
answer
4k
views
io.mockk.MockKException: Missing mocked calls inside every { ... } block: make sure the object inside the block is a mock In Android Kotlin
Mockk Error in android Koltin Unit test. matching with Two URL
io.mockk.MockKException: Missing mocked calls inside every { ... } block: make sure the object inside the block is a mock
@Before
fun ...
0
votes
2
answers
4k
views
Kotlin flow test not emitting all value
I am very new in Unit testing , i am trying to test my flow using Turbine library, it is not emitting all value, here is my test
fun `send function should emit Loading and Content states`() = runTest ...
0
votes
1
answer
216
views
file.exists() returning false in Android unit test
I am trying to test some file related logic in an Android unit test, but whenever I call file.exists() it always returns false for some reason. Here is a boiled down example of a test case I have:
@...
0
votes
1
answer
709
views
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 ...
1
vote
0
answers
432
views
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(...) { ...
2
votes
0
answers
94
views
Check If Service Is Started With Espresso By Click On View
I want to test that when i click on btnRestore , CloudRestoreService should be start.
how to test this ?
@Test
fun testBtnRestore_expectedIntentCloudRestoreService() {
Intents.init()
onView(...
1
vote
1
answer
2k
views
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.
...
3
votes
2
answers
749
views
PhoneNumberUtils.formatNumber is not testable for unit test
This is util method for converting phone number format.
fun String.toDisplayPhoneNumber(): String {
return PhoneNumberUtils.formatNumber(this, Locale.getDefault().country).replace("+82 ",...
0
votes
1
answer
392
views
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 ...
5
votes
1
answer
4k
views
android, how to use mockk to mock BuildConfig.DEBUG
using mockk for unit test, and would like to mock the BuilConfig.DEBUG.
io.mockk.mockkObject(BuildConfig::class) // or mockkStatic
io.mockk.every { BuildConfig.DEBUG } returns true //&...
6
votes
1
answer
860
views
Android Unit test fails with java.lang.IllegalArgumentException: INTERNET permission is required
I am trying to set up unit tests for my application. But I am facing an issue with Segment
This is my test class:
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [Build.VERSION_CODES.O_MR1])
...
0
votes
1
answer
2k
views
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 == ...
1
vote
0
answers
726
views
Android Unit test: Error: EmptyFragmentActivity cannot be cast to BaseActivity. How to get Instance of an Activity which is not defined in Manifest?
I am new to writing Android Test Cases. I am trying to write a test case for a project which is already developed. It has so many Activities and Fragments and we are using Navigation Graph for ...
2
votes
0
answers
405
views
Assert value comparison failed for TestObserver
I have a fake API service that will mock the failure. So when it calls through paging source I should be getting PagingSource.LoadResult.Error of the type returned by API service. This is my test ...
0
votes
1
answer
852
views
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 ...
1
vote
1
answer
593
views
Can I run a list of Robo Scripts?
Is there a way to run a list of Robo Scripts (locally or to Firebase Test Lab) instead of running them one by one?
The way to run Robo Scripts locally one at a time is the following:
java -jar ...
4
votes
1
answer
1k
views
Espresso - Activity never becomes requested state "[RESUMED, STARTED, CREATED, DESTROYED]" (last lifecycle transition = "PRE_ON_CREATE")
If I launch the app manually while espresso test case is running it works and test passed. But If i'm waiting to app launch automatically by espresso. It fails with below information.
Any help please. ...
0
votes
1
answer
601
views
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 (...
0
votes
1
answer
524
views
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 ...
1
vote
0
answers
206
views
update to Android studio (fox) 2020.3.1 patch3 unit test/coverage test not working
Having an android library project working fine with AS 4.1.2.
Just installed Android studio (fox) 2020.3.1 patch 3 without change anything (except set the sdk jre to java 8, version 18.6.0_60, since ...
1
vote
0
answers
1k
views
android unittest got instrument.IllegalClassFormatException, and why it complains "(have Java 1)."?
Having an android library project, it has been built and unit tested fine with android studio 4.1.2. Now change to use android studio (fox) 2020.3.1 path 3.
It starts to get error Cannot run gradle ...
0
votes
1
answer
2k
views
Robolectric + JaCoCo | Issue while running unit test and not generating code coverage
I have added Robolectric to get support of Shadow APIs for writing unit tests. Able to get coverage percentage through default Intellij code coverage tool in Android Studio.
Now trying to add JaCoCo ...
0
votes
1
answer
541
views
android, how to unit test BroadcastReceiver which uses doAsync()
on android app, using Broadcastreceiver to handle the notification click.
public class NotificationReceiver extends BroadcastReceiver {
public void onReceive(final Context context, final Intent ...
0
votes
1
answer
175
views
Unit Test Using Junit5 and mockito
I am trying to write a unit test case for android using Junit-5 and mockito But how to write test case for this kind of function when there is a return statment
```public void doSomething() {
...
2
votes
4
answers
4k
views
NoClassDefFoundError on running unit test after updating Android Studio to ArticFox | 2020.3.1
Test Events were not Received Error:
NoClassDefFoundError on running unit test after updating android studio to ArticFox | 2020.3.1.
Below is the full error:
java.lang.NoClassDefFoundError: jdk/...
0
votes
1
answer
330
views
mockito how to coverage test the inner if block of a static function
Having a static function isNotificationsEnabled which has a if block in the channels for loop to check the notification channel if there is any:
class Utils {
@NonNull
static List<...
5
votes
0
answers
3k
views
Main Looper queued unexecuted runnables
I'm trying to run a unit test on my RecyclerView. For my first test, I want to see if the RecyclerView is displayed.
@RunWith(RobolectricTestRunner::class)
class WordListFragmentTest {
// ...
0
votes
1
answer
645
views
java.lang.NoClassDefFoundError: androidx/sqlite/db/SupportSQLiteQuery in unit test that worked yesterday
The answer to this question is not "Android unit tests cannot access Android stack modules such as the Room database because on your desktop they are all stubbed out."
I had a bunch of unit ...
1
vote
1
answer
2k
views
Robolectric start a fragment that has an observer
How to start a fragment with a LiveData observer in the test scope with Robolectric
Fragment
class MyFragment(private val viewModel: MyViewModel) : Fragment() {
...
fun myObserver {
....
1
vote
0
answers
663
views
RxJava: Scheduler is null while trying to unit test an observable
I'm trying to unit test an observable in a viewmodel but I'm getting the following error. I have included the observable in question...
getRepository()
.executeGetAccount()
...
1
vote
1
answer
283
views
What should I test first with Android Clean Architecture (TDD)
I'm learning TDD with my toy project with Android Clean Architecture.
I want to know how to process my Unit Test.
I want to do TDD with my search features, in this case, Should I create my UseCase and ...
2
votes
0
answers
868
views
Android Biometric unit testing
I need to write Unit test cases for Android Biometric prompt. I tried to search many links but didn't get the proper direction. Need to write unit test cases for UI Biometric is visible or not. Do I ...
1
vote
0
answers
815
views
Android Unit Test Mockito returns null
I'm using Mockito for unit testing.
I want to test my usecase and with mock repository but there's some problem.
I had my repository's function returns arraylist by using mockito. (here's code below)
`...
1
vote
1
answer
1k
views
Unit test two api calls within a method
I have a method that makes an API call and if an error occurs it will retry the call with a different instance of the same service API.
var getResponse = myApi?.getCodeApi()
if (...
0
votes
1
answer
117
views
Unit test fails for coroutine if "by inject{parametersOf("someValue")}" is present within coroutine
I have a coroutine in my viewModel which runs perfectly fine. When I try to unit test the same, it throws the following error "Could not create instance for [type:Factory,primary_type:..MyService&...
0
votes
1
answer
219
views
Unit Testing : Retrofit 2 Exception - API interfaces must not extend other interfaces
I am not extending any interface and all my interfaces are independent. While performing unit testing I am getting the following exception. During normal API calls, everything works fine.
val ...
0
votes
1
answer
1k
views
Unit testing Room android - This job has not completed yet
I am currently unit testing my local data source which uses Room.
I created a test class:
/**
* Integration test for the [WatchListLocalDataSource].
*/
@RunWith(AndroidJUnit4::class)
@MediumTest
...
0
votes
1
answer
399
views
How to unit test coruotine with livedata
On the way of learning unit test with mockK I came across with this scenario:
MyViewModel:
private val _spinner: MutableLiveData<Boolean> = MutableLiveData()
val getSpinner : LiveData<...
6
votes
3
answers
2k
views
How to Unit Test a Room Dao Query that Returns a PagingSource From Paging 3
My question is actually quite generic. I want to know how to unit test a Room Dao query that returns a PagingSource From Paging 3.
I have a Room Dao query:
@Query("SELECT * FROM database"...
6
votes
1
answer
4k
views
When unit testing a viewmodel with a repository that returns a flow, an error happen when converting it to a livedata
I need some help about writing unit tests in android, related to the viewmodel, livedata and flow mechanics and dispatching.
First of all, im writing unit tests, and not instrumeted test.
Actually, im ...
3
votes
2
answers
781
views
android app crawler not working locally via cl
I am trying to run android app crawler: https://developer.android.com/training/testing/crawler
Also looked at this: https://android.jlelse.eu/test-robo-scripts-locally-useful-for-firebase-test-lab-pre-...
5
votes
1
answer
11k
views
Getting error MockKException: no answer found for: Observer(#8).onChanged Android
I'm writing a unit test. Below is my code. The architecture is MVVM using Dagger2. I'm calling the login function residing in the LoginViewModel, which is notifying the getLoginState function. The ...
0
votes
1
answer
502
views
Following Android docs on unit testing and failing
I am trying to run the simple unit test by following the example here:
https://developer.android.com/training/testing/unit-testing/local-unit-tests
import android.content.Context;
import androidx.test....
0
votes
0
answers
133
views
Testing Volley with espresso
I built an android app using volley to fetch data from a remote server.
I am trying to test the app using espresso.
can anyone help me with the code for that?
if I take the simplest example, I am ...