Questions tagged [android-fragmentscenario]
30 questions
21
votes
1 answer
Unit test Dagger Fragments with FragmentScenario
I am trying to test fragment interactions using the Android Jetpack Navigation Component and the fragment-testing library.
My app is using java + Dagger2 as DI.
To test the navigation I have created a JUnit test:
@Test
public void…

Jonas Reif
- 324
- 2
- 5
8
votes
2 answers
How to test interactions with menu when testing fragments with FragmentScenario
I'm trying to test a fragment using FragmentScenario. This fragment has its own menu. There is an add icon on the action bar and clicking on this menu item launches a child fragment from which user can add new items. So I'm trying to test this…

Oya Canli
- 1,996
- 1
- 15
- 27
7
votes
0 answers
How to test vector drawable visible in fragment scenario test?
I have written some fragment scenario tests which would take screenshot and some click event. Few of the test are failed because the imageview is not shown.
It seems the testing activity in the testing library…

Long Ranger
- 5,888
- 8
- 43
- 72
6
votes
2 answers
Android FragmentScenario - Unable to find package androidx.fragment.app.testing
I'm getting this error while trying to use FragmentScenario in Android
error: package androidx.fragment.app.testing does not exist
import androidx.fragment.app.testing.FragmentScenario;
^
This is my simple Unit…

chrizonline
- 4,779
- 17
- 62
- 102
5
votes
0 answers
Testing AppCompatActivity toolbar with FragmentScenario.EmptyFragmentActivity
For my test I launch the fragment in an emtpy activity root view container
@Before
fun init() {
scenario = launchFragmentInContainer(null, R.style.Theme_AppCompat) {
MyFragment()
}
}
and in my fragment, I configure the toolbar to…

the_prole
- 8,275
- 16
- 78
- 163
5
votes
2 answers
Cannot find a version of 'androidx.test:monitor' that satisfies the version constraints
I am getting this error while running a fragment test which is a simple test that launches fragmentInContatiner:
Cannot find a version of 'androidx.test:monitor' that satisfies the version constraints:
Dependency path 'Host…

doersweb
- 231
- 2
- 9
3
votes
1 answer
Failed to build when using fragment testing library on AndroidGradlePlugin 3.5.0 and above for Dynamic Feature module
So, I was trying to use fragment testing library androidx.fragment:fragment-testing:1.2.4 in a dynamic feature module. When I used Android Gradle Plugin (AGP) version 3.6.3, it failed to build with an error
AAPT: error: resource…

Jegul
- 45
- 1
- 5
3
votes
0 answers
Back Button in fragment opens up and closes navigation drawer instead of going back
I have a navigation drawer which is working absolutely fine with drawer icon, however, if I move from navigation drawer activity to any of my fragment, back arrow is also displayed but on clicking of back arrow navigation drawer opens, I just want…

md gouse
- 527
- 1
- 6
- 22
3
votes
3 answers
Fragment testing error: android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class
I am trying to test a fragment, following these instructions: https://developer.android.com/training/basics/fragments/testing
However I am getting the following crash when calling launchFragmentInContainer from my…

tenprint
- 1,123
- 1
- 11
- 29
2
votes
0 answers
Testing a Fragment Scenario with ViewBinding
I'm trying to test a fragment that uses viewBinding to show the views, and a viewModel to fetch that data.
I want to write a UI test to see if certain data is visible or not, but so fare I've had no luck and I'm hoping somebody can help me as I'm…

Claire
- 475
- 1
- 8
- 21
2
votes
1 answer
How to test DaggerFragment with FragmentScenario?
I have a simple Fragment like so:
class SomeFragment : DaggerFragment() {
...
}
Now I want to test this Fragment using FragmentScenario
class LoginFragmentTest {
@Test
fun test() {
launchFragmentInContainer()
…

Archie G. Quiñones
- 11,638
- 18
- 65
- 107
2
votes
2 answers
Showing a Dialog(Dialog Fragment) inside a fragment in UI testing
I am writing UI test cases for a fragment. I am using launchFragmentInContainer to launch fragment independent of activity.
Scenario is, on click of a button, a dialog fragment should be shown but when I do that nothing appears on the screen.
This…

doersweb
- 231
- 2
- 9
1
vote
1 answer
androidTest: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent
I'm trying to run launchFragmentInHiltContainer in androidTest source set.
Running below code fragment causes the mentioned in title error.
@Test
fun mainActivityTest(){
val scenario = launchFragmentInHiltContainer { …

David9809
- 82
- 1
- 1
- 7
1
vote
1 answer
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 {
...
// If I remove this observer the…

Shawn
- 1,222
- 1
- 18
- 41
1
vote
2 answers
On click of an Item Inside recycler view, how can Inflate their respective fragments inside viewpager2?
I have MyViewPager2 adapter with four Fragments and a SemesterFragment that contain recyclerview on it DepartmentRVAdapter. onItem click in the recycler view i want to move to the respective fragment in viewpager2
How can i achieve the below…

sir.p
- 33
- 6