Questions tagged [android-fragmentscenario]

30 questions
1
vote
1 answer

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 fragment with following layout: fragment_main.xml
1
vote
1 answer

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 some test rules (e.g. OkHttpIdlingResourceRule)…
1
vote
2 answers

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 null. There is no problem in production code. My…
1
vote
1 answer

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 viewModel: TrainingListViewModel by viewModels { …
MaxOsH
  • 25
  • 6
1
vote
1 answer

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 would assume that calling moveToState(CREATED) would…
Emmanuel
  • 13,083
  • 4
  • 39
  • 53
1
vote
0 answers

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 NavHostFragment1 which points to main_nav_graph.xml which…
1
vote
1 answer

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

I wrote a test using FragmentScenario: @Test fun test() { launchFragmentInContainer(Bundle().apply { putParcelableArray(MY_DATA, getMyData()) }) // checks here } However, I get following error: Error inflating class…
Rainmaker
  • 10,294
  • 9
  • 54
  • 89
0
votes
2 answers

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 CrimeDetailFragmentTest { private lateinit var fragmentScenario:…
0
votes
2 answers

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 ** **
0
votes
1 answer

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 simulate app being minimized (home button) and…
0
votes
2 answers

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…
bercik
  • 816
  • 1
  • 9
  • 18
0
votes
1 answer

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 FragmentController, i could start it, and I could call…
Stealth Rabbi
  • 10,156
  • 22
  • 100
  • 176
0
votes
2 answers

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 (androidTest) I encounter this error:…
0
votes
1 answer

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 using the back button between the actual app…
0
votes
1 answer

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 what the equivalent approach is for AndroidX…
VIN
  • 6,385
  • 7
  • 38
  • 77
1
2