migrating-from-android-test-classes

Migrate deprecated android.test.* classes to AndroidX Test with JUnit4 and Espresso.

303|10|Updated May 15, 2026
One-click install
npx skills add https://github.com/skydoves/android-testing-skills --skill migrating-from-android-test-classes
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: migrating-from-android-test-classes
Source: https://github.com/skydoves/android-testing-skills/tree/main/platform/legacy/migrating-from-android-test-classes
Command: npx skills add https://github.com/skydoves/android-testing-skills --skill migrating-from-android-test-classes

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Migrating legacy Android instrumentation tests that rely on deprecated android.test.* classes so they keep running under AndroidX Test and can use modern JUnit4, ActivityScenario, and Espresso.

Core Features & Use Cases

  • Class-by-class migration map: Replaces deprecated InstrumentationTestRunner and legacy test base classes with AndroidX Test equivalents (e.g., AndroidJUnitRunner, AndroidJUnit4 runner, InstrumentationRegistry, ApplicationProvider).
  • Modern replacement patterns: Guides mechanical conversions like ActivityInstrumentationTestCase2 → ActivityScenario, ServiceTestCase → ServiceTestRule, and legacy UI/assert/touch helpers → Espresso matchers/actions and supported assertion libraries.
  • Workflow and verification guidance: Provides a safe migration sequence (flip the runner first, convert one test class at a time) and a checklist to confirm android.test.* references are fully removed.

Quick Start

Use the skill to migrate the entire module by switching testInstrumentationRunner to AndroidJUnitRunner first, then converting one legacy android.test.* test class at a time until the module compiles and tests run.

Frequently Asked Questions about migrating-from-android-test-classes

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

FAQPage Schema
How do I migrate deprecated android.test.* classes to AndroidX Test?

To migrate deprecated android.test.* classes to AndroidX Test, switch the test runner to AndroidJUnitRunner, convert classes to JUnit4 with AndroidJUnit4, and map legacy test base classes to modern equivalents like ActivityScenario and ServiceTestRule.

What should I replace ActivityInstrumentationTestCase2 with in AndroidX?

ActivityInstrumentationTestCase2 should be replaced with ActivityScenario in AndroidX. This modern replacement manages activity lifecycle and state transitions, allowing you to launch and control activities safely within instrumentation tests.

How do I migrate ServiceTestCase and ProviderTestCase2 to AndroidX Test?

ServiceTestCase and ProviderTestCase2 should be migrated to ServiceTestRule and the appropriate provider test rules in AndroidX Test. This ensures your service and content provider instrumentation tests run correctly under the modern AndroidJUnitRunner environment.

Can I still use MoreAsserts, ViewAsserts, and TouchUtils in AndroidX Test?

MoreAsserts, ViewAsserts, and TouchUtils are legacy assertion and UI helper classes that should be replaced with supported assertion libraries and Espresso matchers or actions when migrating to AndroidX Test.

What is the safest sequence for migrating legacy Android instrumentation tests?

The safest sequence for migrating legacy Android instrumentation tests is to flip the test runner to AndroidJUnitRunner first, then convert one legacy android.test.* test class at a time, ensuring the module compiles and tests run before proceeding.

Why do my legacy instrumentation tests fail after switching to AndroidJUnitRunner?

Legacy instrumentation tests fail after switching to AndroidJUnitRunner because they still depend on deprecated android.test.* base classes like InstrumentationTestCase and legacy accessors that must be mapped to InstrumentationRegistry and ApplicationProvider.