launching-fragments-with-fragmentscenario

Launch Android Fragments in isolation with FragmentScenario for UI and lifecycle tests.

303|10|Updated May 15, 2026
One-click install
npx skills add https://github.com/skydoves/android-testing-skills --skill launching-fragments-with-fragmentscenario
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: launching-fragments-with-fragmentscenario
Source: https://github.com/skydoves/android-testing-skills/tree/main/instrumentation/scenarios/launching-fragments-with-fragmentscenario
Command: npx skills add https://github.com/skydoves/android-testing-skills --skill launching-fragments-with-fragmentscenario

SYSTEM DOCUMENTATION & REQUIREMENTS

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).

Frequently Asked Questions about launching-fragments-with-fragmentscenario

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I test an Android Fragment in isolation without launching a full Activity?

Use FragmentScenario to launch an isolated Fragment without a full Activity, applying launchFragmentInContainer for UI tests or launchFragment for headless behavior to execute lifecycle and navigation checks.

Why does my FragmentScenario test crash with an AppCompat theme inflation error?

FragmentScenario tests crash with AppCompat theme inflation errors because the default host theme lacks AppCompat attributes, requiring you to pass a specific themeResId when calling launchFragmentInContainer to resolve it.

Do I need both fragment-testing and fragment-testing-manifest dependencies for FragmentScenario?

Yes, you need both dependencies for FragmentScenario: add fragment-testing to androidTestImplementation for the API and fragment-testing-manifest to debugImplementation so the host EmptyFragmentActivity is found.

How do I test Fragment navigation with FragmentScenario when findNavController fails?

Test Fragment navigation with FragmentScenario by installing a TestNavHostController, because the default EmptyFragmentActivity host does not provide a NavHostFragment, causing findNavController calls to fail without it.

Can I move a Fragment to the DESTROYED state immediately when using FragmentScenario?

No, you cannot move a Fragment to the DESTROYED state immediately with FragmentScenario due to lifecycle constraints that reject the initial DESTROYED state, though you can use moveToState and recreate normally.