configuring-junit4-on-android

Configures Ballerina project structure and generates missing files/directories for seamless integration with external apps and tools.

303|10|Updated May 15, 2026
One-click install
npx skills add https://github.com/skydoves/android-testing-skills --skill configuring-junit4-on-android
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: configuring-junit4-on-android
Source: https://github.com/skydoves/android-testing-skills/tree/main/jvm-tests/runner/configuring-junit4-on-android
Command: npx skills add https://github.com/skydoves/android-testing-skills --skill configuring-junit4-on-android

SYSTEM DOCUMENTATION & REQUIREMENTS

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.

Frequently Asked Questions about configuring-junit4-on-android

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

FAQPage Schema
Why is AndroidJUnit4 unresolved in my Android JVM tests?

AndroidJUnit4 is unresolved when using deprecated imports; switch to the canonical androidx.test.ext.junit.runners.AndroidJUnit4 runner to fix the test setup.

How do I fix missing instrumentation errors under Robolectric?

Fix missing instrumentation errors under Robolectric by importing androidx.test.platform.app.InstrumentationRegistry and using ApplicationProvider.getApplicationContext() for Context access.

How do I stop viewModelScope tests from crashing on Dispatchers.Main?

Stop viewModelScope crashes by installing a MainDispatcherRule to reliably substitute Dispatchers.Main, preventing JVM test failures in coroutine consumers like LaunchedEffect.

How do I filter Android tests by size with am instrument arguments?

Filter tests by applying @SmallTest, @MediumTest, or @LargeTest annotations, which wire directly to runner -e size arguments for am instrument size-filtering.

Can I use Truth subjects for Android-aware assertions?

You can use Truth subjects for Android-aware assertions by including the androidx.test.ext:truth dependency to wire robust assertion checks into your test suite.

Do I need a specific Gradle dependency matrix for AndroidJUnit4?

You need a correct Gradle dependency matrix to provide the required AndroidJUnit4 runner, Robolectric, and Truth extensions for reliable Android JVM test execution.