44 questions
1
vote
1
answer
93
views
How to download screenshots created using androidx.test.core.graphics.writeToTestStorage
I'm in the process of changing the Screenshots created by my Android instrumentation tests androidx.test.runner.screenshot.ScreenCaptureProcessor (which worked) to the new androidx.test.core.app....
0
votes
1
answer
161
views
In which package are androidx.test.core.app.DeviceCapture.takeScreenshot or androidx.test.espresso.screenshot.captureToBitmap located
I'm trying to update my screenshot routine used in the instrumentation tests of multiple projects using the new suggested method. Which is, of course, more complicated then the pervious version.
There ...
1
vote
1
answer
516
views
gradle could not resolve androidx library in a java-library
I'm working on setting up instrumentation tests in my java library gradle project using the androidx.test library. I added the following dependency in my build.gradle file:
plugins {
id 'java-...
0
votes
0
answers
189
views
How to test ViewModel using AndroidX and Hilt
I am trying to test my ViewModel class. I believe that I need to use a HiltViewModelTest annotation but, Android Studio cannot find the file..
import androidx.test.ext.junit.rules.ActivityScenarioRule
...
3
votes
1
answer
1k
views
runTest does not run on main thread
I am writing a test and I get this error from a standard library:
java.lang.IllegalStateException: Method addObserver must be called on the main thread
This is my simplified test method:
@Test
fun ...
1
vote
0
answers
645
views
java.lang.NoClassDefFoundError: android/window/OnBackInvokedCallback for ComponentActivity
Running Jacoco results in following error message:
java.lang.NoClassDefFoundError: android/window/OnBackInvokedCallback
at androidx.activity.ComponentActivity.<init>(ComponentActivity.java:...
3
votes
1
answer
386
views
After cleaning gradle, androidx-test.core module throws merged-manifest errors
In a react-native project, ive recently updated to v66.4 from v63.2
after some dependency conflict troubleshooting, i ultimately get a merged manifest error, that indicates suggestions for 3 locations
...
0
votes
1
answer
235
views
Filtering Android Connected Tests
I have a few "connected" tests that are only relevant to run on a specific device model or on a specific brand and should be skipped on other brands/models.
I may be missing something, but ...
8
votes
0
answers
1k
views
How to construct unit tests combining Robolectric and AndroidX with Jetpack Compose?
Assumptions
Robolectric controls which Android version to emulate, so I need this
AndroidX has the test API for Jetpack Compose, so I need this as well
Background
I have experienced a lot of ...
0
votes
1
answer
632
views
How to assert the activity is finished with espresso [duplicate]
I want to assert the activity is finished after clicking a button.
eg: if the user clicked button with id R.id.finish, then the activity is finished.
I'm trying to look up apis with ActivitySenerio ...
4
votes
0
answers
165
views
What is the new preferred approach to running code before and after activity finishes with ActivityScenarioRule?
Previously with ActivityTestRule, one was able to override beforeActivityLaunched and afterActivityFinished to control app state before and after all tests (e.g, implementing a custom rule Class that ...
1
vote
1
answer
2k
views
Error inflating ViewBinding in test class : Binary XML file line #38: Binary XML file line #38: Error inflating class <unknown>
I am trying to write unit tests for a RecyclerView.ViewHolder class which uses ViewBinding but I am facing issues to inflate my ViewBinding in my test class, having this error when running my test :
...
5
votes
2
answers
721
views
Saving bitmap by writeToTestStorage method
I try to make a screenshot test with Espresso:
Test
class ScreenshotTest {
@get:Rule
var nameRule = TestName()
@get:Rule
var mActivityTestRule = ActivityTestRule(MainActivity::class.java)
@Test
...
2
votes
0
answers
936
views
Android UI testing - ActivityScenarioRule is significantly slower then ActivityScenario
I'm getting into Android UI testing, and I learnt two ways to start up activities: ActivityScenario in each test, and ActivityScenarioRule once, annotated with @Rule.
At first I used ActivityScenario, ...
1
vote
0
answers
713
views
Android Unit Test problem : No instrumentation registered! Must run under a registering instrumentation
I followed Android Developer doc and try to make a simple unit test in a Android Project.
But I try to run the unit test with ApplicationProvider.getApplicationContext<Context>()
than I got a ...
1
vote
0
answers
229
views
Cannot resolve symbol ‘ActivityTestRule’ on androidx
I'm trying to test my Activity, but couldn't able to import ActivityTestRule.
My gradle file
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
// Add the Firebase ...
4
votes
1
answer
809
views
FragmentScenario of DialogFragment, onCreateDialog not called
I want to test DialogFragment using androidx.fragment:fragment-testing lib.
I call launchFragmentInContainer and moveToState(Lifecycle.State.RESUMED), but onCreateDialog is not called in this fragment....
4
votes
1
answer
1k
views
java.lang.NoClassDefFoundError: Test Module could not resolve classes of other Feature Module, Unit Testing - Kotlin - Android
I have the following Project Structure:
Main App
--app
--featureModule1
--featureModule2
--TestKit(Library module)
where Testkit has all dependencies including app and featureModules. The Testkit ...
2
votes
1
answer
7k
views
Android Issue::More than one file was found with OS independent path 'androidsupportmultidexversion.txt' "error" [duplicate]
I am getting this issue while compiling my project I have tried a few solutions for that and that is
More than one file was found with OS independent path 'META-INF/LICENSE'
On gradle:3.0.0 ...
3
votes
0
answers
704
views
Why is the main activity not maintained throughout the entire test?
So I'm having some issues with the login of an app.
I've been trying to write an integration test for it...
class LoginIT : AndroidIntegrationTest() {
@get:Rule
var loginActivityRule = ...
1
vote
1
answer
105
views
Dagger2 + ActivityInjection + AndroidXTest/Espresso/RoboElectric in library project
I am working on android library module and I want to test the standalone activity in my module. I was following the article https://medium.com/androiddevelopers/write-once-run-everywhere-tests-on-...
4
votes
0
answers
1k
views
AndroidX Test - ActivityScenario onView() can't find nested child fragment
I have an activity MyActivity which in turn holds a fragment MyFragment. In MyFragment I show a BottomSheetDialogFragment using the childFragmentManager as below:
bottomSheetFragment.show(...
5
votes
0
answers
921
views
Testing BottomSheetDialog item click() with Robolectric and androidx.testing
I'm trying to test a BottomSheetDialog using androidx.test and Robolectric and hitting a problem with trying to click a button in the dialog.
onView(withId(R.id.fab_add)).perform(click())
...
2
votes
1
answer
2k
views
I am confused when to use instrumentation test and when to use unit test
With AndroidX Test Framework now we can run Espresso test as unit test using Robolectric backend . But am confused when to use instrumentation test and when to use unit test.
Let's say we've two ...
1
vote
1
answer
1k
views
How do I import ActivityScenario?
I am attempting to follow the Android ActivityScenario documentation to write Robolectric-based tests. Adding androidTestImplementation "androidx.test.core:app:1.2.0" to my build.gradle allows me to ...
8
votes
1
answer
220
views
Jetpack AndroidX Test "Write Once, Run Everywhere" - But What is the best way to run Everywhere?
Recently I show one of the google IO video about androidX testing which quote "Write Once, Run EveryWhere". Which makes me exciting to learn about androidX testing library.
And what I found that ...
1
vote
0
answers
657
views
Android Studio 3.5.2 androidx test became an unresolved reference
This morning, my android studio updated automatically.
And UI testing with espresso is broken.
The android jetpack test module became an unresolved reference now.
Do you have any solution for it?
...
3
votes
1
answer
1k
views
How to keep tests that test recovery of activities from a bundle in single test suite with other tests using launchActivity
I have a test suite for an android application, testing multiple scenarios. For most of them it makes sense to use AndroidX test framework's launchActivity.
I also have, in the same suite, tests that ...
1
vote
1
answer
2k
views
Robolectric Cannot invoke setValue on a background thread
I am testing an AsyncTask that onPostExecute calls setValue of a LiveData instance. Since I am invoking setValue from onPostExecute no issues were expected regarding the invocation being done by the ...
0
votes
1
answer
272
views
Wrong application instance from ApplicationProvider.getApplicationContext
I am providing my own implementation of Application by creating a subclass and specifying the fully-qualified name of this subclass as the android:name attribute in AndroidManifest.xml's <...
1
vote
0
answers
773
views
Calling click on ViewHolder in Espresso test for RecyclerView does not call the Onclick listener of the view holder
My fragment is as follows
public class NerdLauncherFragment extends Fragment {
private RecyclerView mRecyclerView;
private final String TAG = this.getTag();
@Nullable
@Override
...
2
votes
0
answers
88
views
GrandPermissionRule doesn't work after extending AndroidJUnitRunner
After extending AndroidJUnitRunner GrandPermissionRule stopped working and the test is blocked by permission dialog.
Here is my runner class:
package com.my.package
import android.app.Application
...
1
vote
0
answers
87
views
How to start only SmallTest in Android Studio
I've started a new Project with testautomation. Some tests take some time These have been marked as @LargeTest. There are also some SmallTests (unit tests). The developers need to run the small tests ...
0
votes
1
answer
494
views
How should I properly shutdown my AndroidX Espresso test?
I am writing an Espresso test to test that my App Links are handled properly by my app. I've setup Android Studio and created a test that passes, but the problem is that the test suite hangs. I have ...
2
votes
1
answer
306
views
In which AndroidX library is the androidx.test.annotation package located?
Simple question:
How can I use the androidx.test.annotation package? In which AndroidX library is it located? I'm specifically looking to use androidx.test.annotation.UiThreadTest. This annotation is ...
5
votes
1
answer
3k
views
AndroidTests stopped building after adding androidx.fragment:fragment-testing dependency
After I have added fragment-testing dependency to my project:
// Testing dependencies
espressoVersion = '3.2.0-beta01'
testCoreVersion = '1.1.0'
runnerVersion = '1.1.0'
...
5
votes
1
answer
4k
views
How to configure Android project for AndroidX Test
I am having difficulty configuring my Android application for testing with AndroidX.
When I attempt to run my initial test I get this error:-
FAILURE: Build failed with an exception.
* What went ...
5
votes
0
answers
589
views
How to test options menu using AndroidX fragment test?
Setup
Robolectric: 4.2.1
AndroidX fragment-testing: 1.1.0-alpha05
Background
With AndroidX comes new ways of testing fragments:
Source:
https://developer.android.com/training/basics/fragments/...
1
vote
1
answer
1k
views
AndroidX test dialog
Since AndroidX release we are using Robolectric with Espresso in our unit tests. But we are unable to find a way to test dialogs.
Espresso community suggests we do:
onView(withId(android.R.id.button1)...
2
votes
2
answers
6k
views
How to unit test startActivity?
I am a newbie in testing in android. Please help me write a unit test for this class.
class SplashActivity : AppCompatActivity(){
override fun onCreate(savedInstanceState: Bundle?) {
...
15
votes
1
answer
7k
views
Robolectric AndroidX fragments NoClassDefFoundError
After migration of code and tests to AndroidX, all seems to work pretty well, however Robolectric junit tests for two fragments are failing due to NoClassDefFoundError: androidx/fragment/testing/R$...
6
votes
4
answers
2k
views
No tests found when using custom runner
I'm using androidx.test libraries(which I migrated to recently) in my project and using custom AndroidJUnitRunner.
Before migration it was all working fine but now I'm getting this error -
Started ...
0
votes
0
answers
94
views
Unresolved reference - what's going on?
I'm trying to reference an Activity in a UI test "androidTest" that is part of my main project folder, however, I keep getting the error "Unresolved reference". When I check what's happening, it looks ...
21
votes
3
answers
11k
views
Android Test Orchestrator not working with Android X
I have recently migrated my project to use AndroidX, and have configured test orchestrator for my espresso tests on gradle using the following docs:
https://developer.android.com/training/testing/...