running-instrumented-tests-with-androidjunit4

Configure AndroidX Test dependencies and AndroidJUnit4 runner for instrumentation tests.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It prevents instrumented tests from failing or misbehaving due to an incorrectly configured AndroidJUnit4 runner stack, including dependency wiring, registry imports, Test Orchestrator setup, and hermetic test defaults.

Core Features & Use Cases

  • Correct AndroidX Test dependency matrix: Uses the right artifacts for AndroidJUnit4, InstrumentationRegistry, rules, and Small/Medium/Large filters while avoiding deprecated or legacy imports.
  • Proper Gradle runner configuration: Ensures testInstrumentationRunner is set to the androidx.test.runner.AndroidJUnitRunner class and that runner arguments can be read via the canonical registry API.
  • Test Orchestrator and runtime permission correctness: Installs Orchestrator via androidTestUtil (not androidTestImplementation) and grants permissions using GrantPermissionRule for scoped, revertable permission handling.
  • Flake-reduction defaults: Disables animations via testOptions.animationsDisabled = true and applies the proper @SmallTest/@MediumTest/@LargeTest guidance for size-based filtering.
  • Common failure troubleshooting: Targets issues like “Test runner not found”, “InstrumentationRegistry deprecated”, orchestrator not running, ignored -e args, and instrumentation tests that won’t compile.

Quick Start

Ask an AI coding agent to configure your module’s androidTestImplementation and androidTestUtil dependencies for AndroidX Test 1.7.0/1.3.0, set testInstrumentationRunner to androidx.test.runner.AndroidJUnitRunner, update imports to androidx.test.ext.junit.runners.AndroidJUnit4 and androidx.test.platform.app.InstrumentationRegistry, enable Test Orchestrator under androidTestUtil, and use GrantPermissionRule for runtime permissions while disabling animations.

Frequently Asked Questions about running-instrumented-tests-with-androidjunit4

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

FAQPage Schema
Why are my Android instrumentation tests failing with a test runner not found error?

Android instrumentation tests fail when the AndroidJUnit4 runner stack is misconfigured. Fix this by setting testInstrumentationRunner to androidx.test.runner.AndroidJUnitRunner and using the correct AndroidX Test dependency matrix.

How do I configure Test Orchestrator for Android instrumentation tests in Gradle?

Install Test Orchestrator for Android instrumentation tests using the androidTestUtil dependency rather than androidTestImplementation. This ensures proper installation via the Installation Orchestrator for isolated test execution.

How do I grant runtime permissions in AndroidJUnit4 tests without leaving side effects?

Grant runtime permissions in AndroidJUnit4 tests by using GrantPermissionRule. This provides scoped, revertable permission handling for instrumentation tests, automatically resetting permissions after test execution.

Why is InstrumentationRegistry deprecated in my AndroidX test setup?

InstrumentationRegistry is deprecated when migrating to AndroidX Test because the canonical API moved to androidx.test.platform.app.InstrumentationRegistry. Updating imports to the correct AndroidX artifacts resolves the compilation issue.

How do I disable animations to reduce flaky Android instrumentation tests?

Disable animations to reduce flaky Android instrumentation tests by setting testOptions.animationsDisabled = true in your Gradle file. This hermetic testing default prevents UI animation interference during test runs.

Can I filter Android instrumentation tests by size using annotations?

You can filter Android instrumentation tests by size using @SmallTest, @MediumTest, and @LargeTest annotations. Applying proper size-filtering guidance allows targeted test execution based on test scale.