launching-fragments-with-fragmentscenario
CommunityTest Fragments in isolation with FragmentScenario
Software Engineering#androidx#android instrumentation#fragmentscenario#fragment testing#appcompat theme#navigation testing#fragmentfactory
Authorskydoves
Version1.0.0
Installs0
System Documentation
What problem does it solve?
This Skill helps you test an Android Fragment in isolation without launching a full Activity, while avoiding common crashes related to theming, lifecycle state, fragment factories, and navigation wiring.
Core Features & Use Cases
- FragmentScenario-based isolated launches: use
launchFragmentInContainer<F>()for in-container UI lifecycle andlaunchFragment<F>()for headless fragment behavior. - Correct artifact configuration on Android: handle the required split between
androidx.fragment:fragment-testing(API) andandroidx.fragment:fragment-testing-manifest(manifest-hostedEmptyFragmentActivity) so the host Activity is found. - Theme and navigation gotchas: fix AppCompat/Material theme inflation errors via
themeResId, and addressfindNavController()failures by installing aTestNavHostController(since the default host does not provide aNavHostFragment). - Lifecycle control and safety constraints: drive lifecycle with
moveToState, supportrecreate(), and avoid the invalid initialDESTROYEDstate error.
Quick Start
Add androidx.fragment:fragment-testing to androidTestImplementation, add androidx.fragment:fragment-testing-manifest to debugImplementation, then launch your fragment with launchFragmentInContainer<YourFragment>() (and set themeResId if it uses AppCompat/Material).
Dependency Matrix
Required Modules
None requiredComponents
Standard package💻 Claude Code Installation
Recommended: Let Claude install automatically. Simply copy and paste the text below to Claude Code.
Please help me install this Skill: Name: launching-fragments-with-fragmentscenario Download link: https://github.com/skydoves/android-testing-skills/archive/main.zip#launching-fragments-with-fragmentscenario Please download this .zip file, extract it, and install it in the .claude/skills/ directory.
Agent Skills Search Helper
Install a tiny helper to your Agent, search and equip skill from 471,000+ vetted skills library on demand.