configuring-junit4-on-android
CommunityFix JUnit4 Android test runner setup fast.
Software Engineering#android-testing#robolectric#junit4#androidx-test#instrumentationregistry#applicationprovider#truth-subjects
Authorskydoves
Version1.0.0
Installs0
System Documentation
What problem does it solve?
This skill fixes common Android/JVM test setup failures caused by importing the wrong AndroidJUnit4 and InstrumentationRegistry classes, missing test-size filtering, or forgetting the required coroutine Main dispatcher wiring.
Core Features & Use Cases
- Canonical AndroidJUnit4 runner selection: Use the non-deprecated
androidx.test.ext.junit.runners.AndroidJUnit4so Android framework plumbing works correctly. - Correct registries and Context access: Import
androidx.test.platform.app.InstrumentationRegistryand useandroidx.test.core.app.ApplicationProvider.getApplicationContext()instead of deprecated registry APIs. - Test-size filtering and Truth subjects: Apply
@SmallTest/@MediumTest/@LargeTest(wired to runner-e size) and use Android-aware Truth subjects fromandroidx.test.ext:truth. - Main dispatcher test rule: Install a
MainDispatcherRulepattern soDispatchers.Mainconsumers (e.g.,viewModelScope,LaunchedEffect) don’t crash on the JVM.
Quick Start
Ask an AI coding agent to configure your Android module’s src/test JUnit4 dependencies, runner annotation, InstrumentationRegistry and ApplicationProvider imports, and add MainDispatcherRule plus @SmallTest/@MediumTest/@LargeTest so your tests run and can be filtered by size.
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: configuring-junit4-on-android Download link: https://github.com/skydoves/android-testing-skills/archive/main.zip#configuring-junit4-on-android 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.