Android Programming: The Big Nerd Ranch Guide, 5th Edition
by Bryan Sills, Brian Gardner, Kristin Marsicano, Chris Stewart
Challenge: Testing with FragmentScenario
Much like the ActivityScenario class you used back in Chapter 6, Google has a corresponding FragmentScenario to test fragments in isolation. Built on the same infrastructure as ActivityScenario, FragmentScenario behaves in a similar fashion and uses a similar API. Try writing a test for your CrimeDetailFragment using a FragmentScenario with Espresso.
For example, you could test and verify that the CheckBox and EditText are hooked up to your fragment and update the Crime.
By removing the private visibility modifier on the property and using the FragmentScenario.onFragment(…) function, you can get access to a Crime and perform the appropriate assertions.
FragmentScenario exists in a separate ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access