45 questions
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/...
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$...
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 ...
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 ...
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 ...
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
2 answers
700 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 ...
5 votes
0 answers
916 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()) ...
5 votes
0 answers
575 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/...
4 votes
1 answer
805 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 ...
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 ...
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(...
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 ...