Questions tagged [android-unit-testing]
61 questions
6
votes
1 answer
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])
class LoginViewModelTest {
private lateinit var…

hushed_voice
- 3,161
- 3
- 34
- 66
6
votes
1 answer
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 creating an Unit test for an android app, for…

Marlon López
- 460
- 8
- 21
5
votes
0 answers
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 {
// Executes task sin the Architecture component in the same…

Shawn
- 1,222
- 1
- 18
- 41
5
votes
3 answers
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")
fun getChocolateListData(): PagingSource

rabyunghwa
- 178
- 3
- 24
5
votes
1 answer
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 error I'm getting is:
Error:
…

Ahmad Shahwaiz
- 1,432
- 1
- 17
- 35
4
votes
1 answer
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. Thanks in advance.
Test…

Praveen Kumar Sugumaran
- 331
- 2
- 11
3
votes
2 answers
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-launch-reports-41da83d5769f
The problem is when…

Michael A
- 5,770
- 16
- 75
- 127
2
votes
0 answers
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(withId(R.id.btnRestore))
…

Laksh Lathiya
- 322
- 2
- 12
2
votes
0 answers
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 //<=== throws
but it throws exception
Missing…

lannyf
- 9,865
- 12
- 70
- 152
2
votes
0 answers
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 function
@Test
fun `users paging…

user2934930
- 1,076
- 2
- 12
- 26
2
votes
3 answers
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:…

Varun A M
- 1,103
- 2
- 14
- 29
1
vote
1 answer
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")
}
And this is test code:
@Test
fun…

c-an
- 3,543
- 5
- 35
- 82
1
vote
0 answers
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 navigating the fragments.
I have started writing test…

Aanal Shah
- 1,946
- 2
- 20
- 30
1
vote
1 answer
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 crawl_launcher.jar --apk-file your_app.apk…

Fivos
- 558
- 8
- 19
1
vote
0 answers
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 the project is using…

lannyf
- 9,865
- 12
- 70
- 152