configuring-junit4-on-android

Configure JUnit4 Android unit tests with canonical dependencies and runner implementations.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill resolves common Android unit testing failures caused by incorrect dependency versions, deprecated runner imports, and missing coroutine dispatcher configurations.

Core Features & Use Cases

  • Dependency Management: Provides the canonical Gradle matrix for androidx.test and Truth libraries.
  • Test Infrastructure: Standardizes the use of AndroidJUnit4, InstrumentationRegistry, and ApplicationProvider.
  • Coroutine Support: Implements the required MainDispatcherRule to prevent crashes in ViewModel and Flow tests.

Quick Start

Use the configuring-junit4-on-android skill to set up a new JUnit4 test suite in your Android module by applying the recommended dependency matrix and test rules.

Frequently Asked Questions about configuring-junit4-on-android

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

FAQPage Schema
How do I fix AndroidJUnit4 unit test runtime errors caused by missing coroutine dispatchers?

Fix missing coroutine dispatcher crashes in AndroidJUnit4 tests by implementing the MainDispatcherRule. This standardizes your test infrastructure by ensuring the Main dispatcher is correctly overridden, preventing ViewModel and Flow tests from crashing during local JVM execution.

What Gradle dependencies do I need for a standard JUnit4 Android testing environment?

To set up a standard JUnit4 Android testing environment, apply a canonical Gradle dependency matrix for androidx.test and Truth libraries. This resolves version conflicts and provides the required runner implementations for local JVM unit tests.

Why do my local JVM unit tests fail when accessing Android context?

Local JVM unit tests fail when accessing Android context if test infrastructure uses deprecated runner imports. Standardize your setup by using AndroidJUnit4 alongside InstrumentationRegistry and ApplicationProvider to ensure proper context availability and compliance with androidx.test standards.

Can I use androidx.test annotations for test sizing in JUnit4 Android modules?

Yes, you can use androidx.test annotations for test sizing in JUnit4 Android modules. Enforcing compliance with androidx.test standards for test size annotations ensures your local JVM tests are correctly categorized and executed within the standardized testing environment.

What's the best way to configure JUnit4 tests for Android ViewModel and Flow?

The best way to configure JUnit4 tests for Android ViewModel and Flow is to implement a MainDispatcherRule. This coroutine-aware test execution setup prevents runtime crashes by correctly configuring the Main dispatcher before running your local JVM tests.