Skip to main content
Filter by
Sorted by
Tagged with
0 votes
0 answers
28 views

Android FragmentScenario androidTest prevent running network calls on launch and view model testing

I have an existing fragment class as part of a navigation graph component and uses Dagger to create instances of ViewModels scoped to the nav graph. However, I have a few questions about ...
MajinKenn's user avatar
0 votes
2 answers
211 views

How to get access to a property from the test class? FragmentScenario, Espresso

I want to check my editTextView and the field of a property(crime.title). How could I get this field from the test class? That's my Test Class: @RunWith(AndroidJUnit4::class) class ...
Viktor's user avatar
  • 23
2 votes
1 answer
1k views

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 = ...
David9809's user avatar
  • 102
0 votes
2 answers
128 views

Errors in connection of CameraFragment.kt with xml

I need help please, i'm getting errors in fragment.kt in process of getting a camera set up ** //fragmentcamera.xml ** **<?xml version="1.0" encoding="utf-8"?> <...
Anika Sabah's user avatar
3 votes
0 answers
1k views

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 ...
Claire's user avatar
  • 485
1 vote
1 answer
2k views

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 { ....
Shawn's user avatar
  • 1,372
1 vote
2 answers
260 views

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 ...
sir.p's user avatar
  • 33
0 votes
1 answer
1k views

testing androidx.fragment lifecycle by stopping and resuming with FragmentScenario, onCreateView() called twice but this bug is already fixed in 1.3.1

I'm writing instrumented tests for my app using androidx.fragment:fragment-testing. One of test cases is to check if all underlying logic behaves correctly when Fragment is stopped and resumed, to ...
Piotr Śmietana's user avatar
1 vote
1 answer
741 views

Styling issue when using FragmentScenario

When using FragmentScenario from androidx.fragment:fragment-testing to test fragment UI, not all styles are applied correctly. As an example, there's very simple application that just presents ...
Gawcio's user avatar
  • 1,175
0 votes
2 answers
341 views

android fragment scenario crashes during snackbar creation

I've got android application. I'm writing test using fragment scenario to test my fragment. My test is simple and looks like this: FragmentScenario.launchInContainer(ShoppingPlanningFragment.class); .....
bercik's user avatar
  • 906
7 votes
0 answers
188 views

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 ...
Long Ranger's user avatar
  • 6,008
1 vote
1 answer
918 views

Fragment testing, I'm missing something equivalent to ActivityScenarioRule

I'm used to test my Fragments by launching the Activity containing it in an Espresso test. This has been working pretty nicely and I have been able to control the test environment/execution through ...
pmellaaho's user avatar
  • 792
1 vote
2 answers
3k views

fragment arguments are null using launchFragmentInContainer

I am writing a test for a fragment that uses safeArgs and FragmentScenario, however when I call launchFragmentInContainer() with the fragmentArgs parameter, I get an exception saying the arguments are ...
or_dvir's user avatar
  • 619
5 votes
0 answers
1k views

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() } } ...
the_prole's user avatar
  • 8,895
3 votes
1 answer
722 views

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 ...
Jegul's user avatar
  • 45
0 votes
1 answer
196 views

Moving from FragmentController to FragmentScenario

I'm using robolectric and am updating my support fragments to androidx fragments. THis means updating tests that use FragmentController<> to the recommended FragmentScenario. With ...
Stealth Rabbi's user avatar
1 vote
1 answer
2k views

FragmentScenario doesn't work as expected

I'm using almost the as same architecture as Google sample: GithubBrowserSample. This field is injected in my Fragment class: @Inject lateinit var viewModelFactory: ViewModelProvider.Factory val ...
MaxOsH's user avatar
  • 25
0 votes
2 answers
963 views

Fragment testing: Only the original thread that created a view hierarchy can touch its views

I'm struggling for a certain amount of time so I decided to ask for help here... I'm using almost the as same architecture as Google sample: GithubBrowserSample. In the test of one of my fragment (...
MaxOsH's user avatar
  • 25
7 votes
2 answers
3k views

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; ...
chrizonline's user avatar
  • 4,979
1 vote
1 answer
342 views

FragmentController vs FragmentScenario

Roblectric's FragmentController allowed us to drive the lifecycle of the Fragment to a desired state. It seems that FragmentScenario always takes the Fragment under test to its resumed state. One ...
Emmanuel's user avatar
  • 13.2k
1 vote
0 answers
297 views

Using FragmentScenario with nested NavHostFragments makes certain navigations impossible to verify during testing

In my app I have a MainActivity that holds a NavHostFragment. That NavHostFragment is used to display Fragments, some of which have their own NavHostFragments. For example, MainActivity hold ...
neonDion's user avatar
  • 2,348
0 votes
1 answer
756 views

FragmentScenario and nested NavHostFragments don't perform navigations as expected in Instrumentation tests

I am writing a single Activity app that uses Android's Navigation Components to help with navigation and Fragment Scenario for instrumentation testing. I have run into a performance discrepancy when ...
neonDion's user avatar
  • 2,348
3 votes
0 answers
230 views

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 ...
md gouse's user avatar
  • 527
0 votes
1 answer
881 views

Testing AndroidX fragments on JVM only (without launching an emulator/device)

I'm looking for a way to unit test my AndroidX fragments without the need launch the fragment in an emulator. Robolectric allows us to run our unit tests for activities in the JVM, but I'm not sure ...
VIN's user avatar
  • 6,907
2 votes
1 answer
1k views

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() { ...
Archie G. Quiñones's user avatar
8 votes
2 answers
1k views

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 ...
Oya Canli's user avatar
  • 2,506
2 votes
2 answers
1k views

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 ...
doersweb's user avatar
  • 231
5 votes
2 answers
6k views

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 ...
doersweb's user avatar
  • 231
3 votes
3 answers
1k views

Fragment testing error: android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class <unknown>

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 ...
tenprint's user avatar
  • 1,157
21 votes
1 answer
2k views

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 ...
Jonas Reif's user avatar
1 vote
1 answer
403 views

Error inflating class com.google.android.material.tabs.TabLayout inside FragmentScenario test

I wrote a test using FragmentScenario: @Test fun test() { launchFragmentInContainer<MyFragment>(Bundle().apply { putParcelableArray(MY_DATA, getMyData()) }) // checks here } However, I ...
Rainmaker's user avatar
  • 11.1k