configuring-junit4-on-android

Community

Fix JUnit4 Android test runner setup fast.

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.AndroidJUnit4 so Android framework plumbing works correctly.
  • Correct registries and Context access: Import androidx.test.platform.app.InstrumentationRegistry and use androidx.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 from androidx.test.ext:truth.
  • Main dispatcher test rule: Install a MainDispatcherRule pattern so Dispatchers.Main consumers (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 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: 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.
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.