Questions tagged [android-testing]
The Android testing framework
2,160
questions
0
votes
1
answer
16
views
Testing Koin viewmodel: Cannot invoke setValue on a background thread
Trying to create JUnit test for Viewmodel using Koin DI. Running the first test I've got this issue: Cannot invoke setValue on a background thread. So how should I test Viewmodel correctly?
Test:
...
0
votes
0
answers
18
views
Espresso tests fail randomly with AppNotIdleException
I'm writing very long-running UI/integration tests, intending to go through the entire functionality of my app under various configurations, and I'm having problems with the overall stability and ...
0
votes
1
answer
61
views
Mock current location for android testing
Is there a way to mock the current location on an android device for testing without using another mock location provider app?
I have a navigation app that I need to do some instrumentation tests on ...
0
votes
0
answers
42
views
OkHttp MockWebServer throws java.net.SocketTimeoutException: timeout - exception
I'm using OkHttp's MockWebServer for API mocking in my Android instrumentation tests. It's been effective so far, but I've encountered an issue where making a second call to the same endpoint within ...
0
votes
0
answers
38
views
Instrumented test uses main AndroidManifest instead of the test version
I am trying to uses OkHttp in some Android instrumented tests, but I get the following error:
java.net.UnknownServiceException: CLEARTEXT communication to localhost not permitted by network security ...
0
votes
0
answers
9
views
Android UI Tests Only Show Skipped Tests in Gradle Output
When I run just the UI tests on a gradle managed device it only shows Skipped tests in the out put. I have set up the logging level but it is ignore it for UI tests. Am I missing something?
...
0
votes
1
answer
40
views
Espresso onData with check (assertion) on data object instead of View
I have a ListAdapter for objects of type Foo. These objects have fields int id and double quantity.
In my Espresso tests, I would like to assert that the data entry with id = 5 has quantity = 10.
(...
0
votes
0
answers
74
views
Android studio test not running says 0 passed and tests cancelled
Here's the repo. This is what I see. And this is another warning that appears.
I can see the test running in the emulator only when I run the whole androidTest folder, but IDE doesn't seem to know ...
1
vote
0
answers
28
views
Updating Android material version causes Firebase tests to fail for but still passes locally
Recently I updated com.google.android.material:material from 1.4.0 to 1.9.0 and noticed FTL tests on TextInputLayout with MaterialAutoCompleteTextView started to fail consistently.
After some version ...
0
votes
0
answers
51
views
Is it ok in android to read from file strings.xml in unit tests to ensure that resource is matches required string?
I want to achieve 100% code coverage in unit tests, and I realized that nobody writes unit tests that read strings.xml to ensure that a resource with a given ID has the expected value. The same can be ...
0
votes
0
answers
37
views
How do I write a test for the failing request to an API made in the viewModelScope in Android?
I have a view model which creates a mutable state using a sealed interface.
My question is How do I write a test when the repository returns a Result.failure(e) in order to assert that the marsUiState ...
0
votes
0
answers
26
views
How to generate an Espresso test report from the command line [duplicate]
When running Espresso tests from the command line, I need to also generate a test report.
I run my tests from the command line in the standard way:
adb -d shell am instrument -w -e log true -e package ...
0
votes
1
answer
29
views
Android Kaspresso (Kakao) how to pick file from downloads
How to pick file from Downloads folder with Kaspresso/Kakao/UI Automator? Cannot find any info about it.
0
votes
0
answers
23
views
how to make correct test
I try to make test of this with mockk but I can't make it because of Coroutine.
notesUseCases.getAllNotesUseCase.invoke() returns Flow<List<Note>>, and note is something like this Note(1, &...
1
vote
1
answer
122
views
Jetpack compose testing : how to getcurrent activity after starting new activity from testrule
How to get current activity ( newly started activity ) , started from ui testing. Is there anyway to get its instance using composeTestRule
0
votes
0
answers
41
views
Test case failing: ClassCastException: androidx.lifecycle.ViewModel$Subclass1 cannot be cast to class SecondChildViewModel
Having parent and child Activities & viewModels. My assumption is always taking parent viewmodel and not able to take child viewModel. so that my test cases are failing.
viewModels are like
...
0
votes
0
answers
62
views
Can i use espresso to test jetpack compose UI
I have an existing test automation framwork that i want to reuse for a testing of new android application built in jetpack compose
I found a way to put resource ids in compose ui element but espresso ...
0
votes
0
answers
19
views
Use custom test runners for android Unit Test
Is it possible to use a custom test runner for android unit test? (Or junit tests)?
I have tried setting a custom test runner in my default config like
testInstrumentationRunner = "ca.xyz....
0
votes
0
answers
15
views
How to fix gradle build error: Could not get property 'androidXTestVersion0' for object
I'm trying to set up instrumented unit testing for an android app by following the android documentation here. I've verified that the google maven repository is listed in the repositories section of ...
0
votes
0
answers
15
views
setAdvertiseMode in android.bluetooth.le.AdvertiseSettings$Builder not mocked
I am writing Junit test cases using mockito for myclass
it is using jUnt mockit with the help of junit4
InternalBluetoothManager @Inject constructor(
private var context: Context,
private ...
0
votes
0
answers
53
views
How get TextField from custom view use onNodeWithTag if tag on parent box
For test UI I use code
composeTestRule.onNodeWithTag(usernameFieldTag).performTextInput(testUser)
But my Text field is custom and I send testTag in parent view (Column)
AppTextField(modifier: ...
0
votes
1
answer
245
views
In kotlin, Failed to instantiate test runner class androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
I started learning android testing.
I'm trying to test with Mockk library and androidJUnit4 Runner.
But the instantiation is failed.
I could have misunderstanding about testing features.
What would be ...
0
votes
0
answers
71
views
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/myproject/mymodule/ClassName in Android Instrumented Tests
can anyone help to solve this problem?
Previously, i try to create a instrumented test for my project. I create new module for unit test and an error occurred in the module when I created the class, ...
0
votes
0
answers
98
views
How to provide image as a fake Camera frame in UI testing with CameraX?
I'm using CameraX in my application having image analysis + preview use case. I want to write a UI test (Espresso or UI Automator) by which I can inject a fake image as a source of the Camera and want ...
1
vote
1
answer
270
views
Android MacroBenchmark: FrameTimingMetric test is running only for 1 iteration
I am trying to perform a scroll test on a recycler view using FrameTimingMetric for 5 iterations.
My AppStartup Test using StartupTimingMetric() is working fine and generating results for all 5 ...
0
votes
0
answers
13
views
assertHistorySize() for State or MutableState in Android Test
I am used to use awaitValue + assertHistorySize to test how much a LiveData has received and what it has got.
So I write the following code (only as an example):
val dataObserver = viewModel.data()....
0
votes
0
answers
311
views
Navigation destination is not a direct child of this NavGraph
I just passed new variable in navigation graph while opening a new screen and android tests start failing with the error that destination is not a direct child of this NavGraph. I updated graph as:
...
0
votes
0
answers
19
views
HiltExt for testing fragment on Android 31+ failed: requires flag_immutable on PendingIntent
I'm testing the fragment, using HiltExt to inject the activity during the test.
But my project is targeted on sdk 31, so when I run a test case, it's failed with this error:
java.lang....
0
votes
0
answers
9
views
Button in child of rv changes how to test: Android
I have a recyclerView with a bunch of childs. Each child has an ImageButton to mark as favourite. Once you click the fav button, the image changes from a white bookmarck with a gray border to a yellow ...
0
votes
1
answer
99
views
Testing MutableStateFlow in Android Compose?
I have the following code:
ViewModel:
private val _prefix = MutableStateFlow("")
val prefix: StateFlow<String> = _prefix
private val _firstName = MutableStateFlow("")
...
0
votes
0
answers
14
views
It is possible to register a broadcast receiver in my androidtest case?
My code doest not work, onReceive never called.
@Test
fun receive_broadcast() {
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
val uiDevice = ...
0
votes
0
answers
9
views
Best way to call and add/clear contacts in android instrumentation tests
What is he best way to add/clear contacts, start calls and register/unregister phone accounts for android instrumentation/emulator tests.
I do not want to add any kind of permissions such as ...
0
votes
0
answers
72
views
Android Instrumentation test failing
I am trying to write a test oAuth2 login through custom tab and capture the code through deep link from custom tab. I Expect that test should be passed. But it failed the following log.
java.lang....
0
votes
0
answers
118
views
How to use hilt for testing in a multi module android project?
I’ve couple of questions when trying to use hilt for testing in a multi-module project:
Say I’ve a feature module which declared some interface and its classes depend upon that interface. The ...
1
vote
0
answers
19
views
android testing state flow test block
I am writing tests for my view model and I encountered an issue, did some research and I found this on docs and using that I fixed my problem but have my question unanswered
https://developer.android....
0
votes
0
answers
44
views
Appium Inspector: Call to 'tap' failed
I am having a problem with this program. When I select a button it throws me that error and I can't continue. Anyone know what might be happening?
You can see the problem hereImage of the tap error
...
0
votes
0
answers
22
views
Cannot UnitTest my repository with Firebase
I'm trying to run my unit test that contains Firebase code, I have mocked everything that I need and also initialized FirebaseApp.initialize(context) before running my test.
This is my test code
@...
0
votes
0
answers
29
views
Execution failed for task ':mobile:processGoogleDebugAndroidTestResources'
I am trying to run a simple test for my Application but I get a resource linking error for the androidTest Manifest.
Here is the error:
* What went wrong:
Execution failed for task ':mobile:...
0
votes
0
answers
29
views
Where is data stored during an Android test?
I am providing a DataStore<Preferences> to be able to conveniently edit preferences.
/**
* Default data store
*/
val Context.settingsDataStore: DataStore<Preferences> by ...
0
votes
0
answers
46
views
Room database test fails when I call another operation within same coroutine context
I have a repository that has a DAO. I use this repo to store a coin object inside Room database.
My repo is the following:
class CoinPickerRepoImpl @Inject constructor(
private val coinDao: ...
1
vote
0
answers
288
views
Hilt injection with android instrumented tests
I am running into the following exception when running a test for a composable that injects a hilt view model, eg:
@Composable
fun MyScreen(
viewModel: MyViewModel = hiltViewModel()
) {
}
...
0
votes
1
answer
52
views
Error using Hilt instrumentation TestCase Installin for SingletonComponent
I'm getting the following Hilt error when I try to use a TestCase module to provide mocks for my instrumentation testing.
Here is the error
[Hilt]
public final class TestModules {
^
@...
0
votes
1
answer
373
views
Android. How to test composable function?
I have composable function winch just transform one object to another (state). Here is my code:
@Composable
fun Walpaper.toMaterialState(): MaterialState {
return MaterialState(
price = if ...
2
votes
0
answers
149
views
Mockito mock not returning paging/flow data
I am running into an issue trying to mock paging data coming from a repository. Here is the portion in my viewmodel I would like to test:
// watch for filter to change, on charge reset the paging ...
0
votes
0
answers
186
views
How to get uiautomatorviewer on windows 10
I have downloaded android SDK platform tools, but could not find uiautomatorviewer inside it. i am using windows 10 and could not find any documentation regarding uiautomator viewer. Could somebody ...
0
votes
1
answer
75
views
How can I create a code template in Android Studio to replicate the val template in Kotlin
Kotlin and Java code templates in Android Studio.
I tried to create a code template for the truth library that would work like the val template works i.e,
When you want to create a variable from the ...
0
votes
0
answers
13
views
How to see Description on matchesSafely function when our class is extends with BoundedDiagnosingMatcher in Espresso
I've tried many method, but I still cannot see the description inside matchesSafely function. And I've tried to research any related articles but there are still few articles that discuss it.
For make ...
0
votes
0
answers
80
views
How to select View that inside of 2 or more Include layout by its id with Espresso
I'm trying to reach a View which included in include layout with Espresso, within its id. But I always got this error:
androidx.test.espresso.NoMatchingViewException: No views in hierarchy found ...
0
votes
0
answers
78
views
How to use multiple CTS media files when running test modules on Android Test Station
I am running CTS tests on Android Test Station and am facing an issue. It is regarding these three test cases:
CtsMediaTestCases
CtsMediaStressTestCases
CtsMediaBitstreamsTestCases
All three of them ...
0
votes
0
answers
32
views
How to test if after pressing a button it goes to the next window
I am making an app that has a quizz with Jetpack Compose. The quizz gives you a question and 4 answers to choose from, but it also comes with a 'Next' button in case you want to skip the question. I ...