using-robolectric-correctly

Configure Robolectric shadows, loopers, and test runners for Android unit tests.

Updated Jul 20, 2026
One-click install
npx skills add https://github.com/trancee/MeshLink-template --skill using-robolectric-correctly-trancee
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: using-robolectric-correctly
Source: https://github.com/trancee/MeshLink-template/tree/main/.agents/skills/android-testing-skills/jvm-tests/robolectric/using-robolectric-correctly
Command: npx skills add https://github.com/trancee/MeshLink-template --skill using-robolectric-correctly-trancee

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill resolves the friction of testing Android-dependent code by providing a reliable, high-speed JVM environment that avoids the overhead of emulators while preventing common configuration and runtime pitfalls.

Core Features & Use Cases

  • Environment Configuration: Correctly sets up @Config annotations, SDK matrices, and includeAndroidResources to prevent common startup crashes.
  • Looper & Shadow Management: Provides precise control over the main looper and system shadows to ensure asynchronous code is tested deterministically.
  • Migration & Best Practices: Guides the transition from legacy sharedTest patterns to modern KMP-style source sets and ensures proper runner selection between AndroidJUnit4 and RobolectricTestRunner.

Quick Start

Use the using-robolectric-correctly skill to configure my test class and resolve the current ResourcesNotFoundException.

Frequently Asked Questions about using-robolectric-correctly

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

FAQPage Schema
How do I fix ResourcesNotFoundException when running Robolectric tests on the JVM?

To resolve ResourcesNotFoundException in Robolectric, enable includeAndroidResources in your build configuration and ensure compliance with AGP 7.2+ source set requirements. This properly links Android resources to your JVM test environment.

How do I test asynchronous Android code deterministically using Robolectric?

To test asynchronous Android code deterministically with Robolectric, use precise looper draining and system shadow management. This ensures background tasks execute predictably without emulator overhead during your unit tests.

Should I use AndroidJUnit4 or RobolectricTestRunner for my Android unit tests?

Choose between AndroidJUnit4 and RobolectricTestRunner based on your integration needs. Proper runner selection ensures correct AndroidX test library integration and reliable JVM simulation of Android-dependent components.

How do I configure @Config annotations and SDK matrices for Robolectric?

Configure @Config annotations and SDK matrices to specify target Android SDK levels and custom shadow packages. Proper environment configuration prevents common startup crashes and ensures reliable Android framework simulation on the JVM.

How do I migrate legacy sharedTest patterns to modern source sets for Robolectric?

Migrate legacy sharedTest patterns to modern KMP-style source sets to align with AGP 7.2+ requirements. This transition ensures proper test runner selection and correct integration of AndroidX test libraries for your JVM tests.