launching-fragments-with-fragmentscenario

Community

Test Fragments in isolation with FragmentScenario

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 and launchFragment<F>() for headless fragment behavior.
  • Correct artifact configuration on Android: handle the required split between androidx.fragment:fragment-testing (API) and androidx.fragment:fragment-testing-manifest (manifest-hosted EmptyFragmentActivity) so the host Activity is found.
  • Theme and navigation gotchas: fix AppCompat/Material theme inflation errors via themeResId, and address findNavController() failures by installing a TestNavHostController (since the default host does not provide a NavHostFragment).
  • Lifecycle control and safety constraints: drive lifecycle with moveToState, support recreate(), and avoid the invalid initial DESTROYED state 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 required

Components

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.
View Source Repository

Agent Skills Search Helper

Install a tiny helper to your Agent, search and equip skill from 471,000+ vetted skills library on demand.