home / skills / hitoshura25 / claude-devtools / android-espresso-dependencies

android-espresso-dependencies skill

/skills/android-espresso-dependencies

This skill adds Espresso and AndroidX Test dependencies to your Android project and guides optional test runner configuration.

npx playbooks add skill hitoshura25/claude-devtools --skill android-espresso-dependencies

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
3.2 KB
---
name: android-espresso-dependencies
description: Add Espresso and AndroidX Test dependencies to Android project
category: android
version: 1.0.0
inputs:
  - project_path: Path to Android project
outputs:
  - Updated app/build.gradle.kts with test dependencies
verify: "./gradlew dependencies | grep espresso"
---

# Android Espresso Dependencies

Adds Espresso and AndroidX Test dependencies required for E2E UI testing.

## Prerequisites

- Android project with Gradle
- Kotlin DSL (build.gradle.kts)
- Minimum SDK 21+ (Espresso requirement)

## Inputs

| Input | Required | Default | Description |
|-------|----------|---------|-------------|
| project_path | Yes | . | Android project root |

## Process

### Step 1: Add Espresso Dependencies

Add to `app/build.gradle.kts`:

```kotlin
dependencies {
    // Existing dependencies...

    // Espresso core
    androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
    androidTestImplementation("androidx.test.espresso:espresso-contrib:3.5.1")
    androidTestImplementation("androidx.test.espresso:espresso-intents:3.5.1")

    // AndroidX Test
    androidTestImplementation("androidx.test:runner:1.5.2")
    androidTestImplementation("androidx.test:rules:1.5.0")
    androidTestImplementation("androidx.test.ext:junit:1.1.5")
    androidTestImplementation("androidx.test.ext:junit-ktx:1.1.5")
}
```

**Detection logic:**
- Check if dependencies already exist (don't duplicate)
- Use latest stable versions
- Keep existing test dependencies

### Step 2: Configure Test Runner (Optional)

If user wants test orchestrator for better isolation:

```kotlin
android {
    // ... existing config ...

    defaultConfig {
        // ... existing config ...
        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
    }

    testOptions {
        execution = "ANDROIDX_TEST_ORCHESTRATOR"
        animationsDisabled = true
    }
}

dependencies {
    // ... existing dependencies ...
    androidTestUtil("androidx.test:orchestrator:1.4.2")
}
```

**Ask user:** "Enable test orchestrator for better test isolation? (Recommended for large test suites)"

## Verification

**MANDATORY:** Run these commands:

```bash
# Sync Gradle
./gradlew dependencies --configuration androidTestRuntimeClasspath

# Verify Espresso dependencies
./gradlew dependencies | grep espresso && echo "✓ Espresso dependencies added"

# Verify AndroidX Test dependencies
./gradlew dependencies | grep "androidx.test" && echo "✓ AndroidX Test dependencies added"
```

**Expected output:**
- ✓ Espresso dependencies added
- ✓ AndroidX Test dependencies added

## Outputs

| Output | Location | Description |
|--------|----------|-------------|
| Dependencies | app/build.gradle.kts | Espresso and AndroidX Test libs |

## Troubleshooting

### "Dependency resolution failed"
**Cause:** Version conflict with existing dependencies
**Fix:** Check for conflicting androidx.test versions, align all to same version

### "Minimum SDK too low"
**Cause:** minSdk < 21
**Fix:** Espresso requires API 21+, update minSdk in defaultConfig

## Completion Criteria

- [ ] Espresso dependencies in app/build.gradle.kts
- [ ] AndroidX Test dependencies in app/build.gradle.kts
- [ ] Test runner configured
- [ ] `./gradlew dependencies` shows espresso libraries

Overview

This skill adds Espresso and AndroidX Test dependencies and optional test orchestrator configuration to an Android Gradle project using Kotlin DSL. It ensures required test libraries are present, avoids duplicate entries, and verifies installation via Gradle dependency checks. The skill targets projects with minSdk 21+ and Kotlin-based build.gradle.kts files.

How this skill works

The skill inspects app/build.gradle.kts for existing androidTest dependencies and injects Espresso and AndroidX Test artifacts only if they aren’t already present. It can also modify defaultConfig and testOptions to set the AndroidJUnitRunner and enable the AndroidX Test Orchestrator, and it adds androidTestUtil for the orchestrator when requested. After changes it runs Gradle dependency queries to confirm the libraries are visible on the androidTest runtime classpath.

When to use it

  • You want to add end-to-end UI testing support with Espresso.
  • Setting up CI or local test runs that require AndroidX Test runner and rules.
  • Migrating or upgrading test dependencies to current stable Espresso and AndroidX Test versions.
  • Enabling test isolation via AndroidX Test Orchestrator for flaky or large test suites.

Best practices

  • Run this on projects using Kotlin DSL (build.gradle.kts) and with minSdkVersion >= 21.
  • Detect existing androidTest dependencies first to avoid duplicates or version conflicts.
  • Pin AndroidX Test and Espresso versions consistently across modules to prevent resolution issues.
  • Consider enabling the orchestrator only for larger suites; it adds apk-level isolation and requires androidTestUtil.
  • After modification, run the provided Gradle verification commands to ensure dependencies are resolved.

Example use cases

  • Add espresso-core, espresso-contrib, espresso-intents and AndroidX Test libs to a new app module.
  • Enable AndroidJUnitRunner and orchestrator for CI to reduce cross-test interference.
  • Audit a legacy app’s test deps and upgrade to the stable Espresso 3.5.1 and AndroidX Test 1.5.x versions.
  • Automate dependency injection in a monorepo script that updates multiple app modules.

FAQ

My project uses Groovy build scripts (build.gradle). Can I use this skill?

This skill is designed for Kotlin DSL (build.gradle.kts). For Groovy builds you can apply the same dependency coordinates manually or convert the script to Kotlin DSL first.

Gradle dependency resolution failed after adding, what should I check?

Check for conflicting androidx.test or espresso versions across modules and align them. Also confirm minSdk >= 21 and that the dependency was added to the app module, then rerun ./gradlew dependencies --configuration androidTestRuntimeClasspath.