- Fragments Overview
- Fragments are reusable UI containers for different activities
- Fragments shouldn't depend on specific parent activities
- Fragment view hierarchy should only be created when visible
- Testing Setup
- FragmentScenario class provides lifecycle state management
- Fragment-testing-manifest and fragment-testing artifacts needed
- Testing uses Espresso and Truth libraries
- Fragment Launch Methods
- launchInContainer() tests fragment's UI with root view controller
- launch() tests fragment without UI, attached to empty activity
- FragmentScenario drives fragment to RESUMED state by default
- Advanced Features
- FragmentFactory allows testing dependencies
- moveToState() simulates fragment lifecycle state changes
- recreate() destroys and recreates fragment on low-resource devices
- FragmentScenario supports testing dialog fragments