Chapter 2 of 11
Setting Up Your Java Mobile Testing Environment
Before a single test runs, the wrong SDK version or missing driver can derail your day. Assemble a reliable local setup for Android and iOS testing with Java so your tooling stops getting in the way.
Step 1: Big Picture – What You Are Setting Up
Four Layers of Your Stack
You will set up four layers: 1) Java + build tools + IDE, 2) Android and iOS SDKs, 3) Appium server and drivers, and 4) your Java test project structure.
Role of Appium
Your Java tests send WebDriver-style commands via the Appium Java client to the Appium server, which delegates to UiAutomator2 (Android) or XCUITest (iOS).
End Goal
By the end, you can run a skeleton Java test on an Android emulator and have your environment ready to add iOS simulator tests on macOS.
Step 2: Install and Verify the JDK and Build Tool
Pick a Stable JDK
Install an LTS JDK, ideally Temurin or Oracle JDK 17. Confirm with `java -version` and `javac -version` that Java 17 is on your PATH.
Add Maven
Install Maven 3.9.x+, add it to PATH, and run `mvn -version` to confirm it sees Java 17. We will use Maven to manage Appium and test dependencies.
Why Versions Matter
Appium Java client and Android tooling are tested mostly on Java 11/17. Using these avoids hidden incompatibilities, especially in CI.
Step 3: Configure Your IDE for Java Mobile Testing
Choose Your IDE
Use IntelliJ IDEA for a clean Java test project, or Android Studio if you also work on Android app code and need integrated SDK and AVD tools.
Set Project JDK
In IDE settings, set the Project SDK to your JDK 17 installation and the language level to Java 17 or lower to avoid runtime mismatches.
Typical Team Setup
Many teams use Android Studio mainly for SDKs and emulators, and IntelliJ IDEA for the Appium Java test repo to keep things lean.
Step 4: Android Studio, Android SDK, and AVDs
Install Android Studio + SDK
Install the latest Android Studio and let it install the Android SDK, platform-tools, and at least one Android platform (for example, Android 14).
Check adb and PATH
Run `adb version`. If it fails, add the `platform-tools` folder from your Android SDK to PATH so Appium can talk to devices.
Create and Verify an AVD
Use Android Studio Device Manager to create a Pixel emulator. Launch it, then run `adb devices` and confirm it appears as an attached device.
Step 5: Xcode, iOS Simulators, and macOS Requirements
macOS Is Required for iOS
To run iOS tests with Appium, you must use macOS with a recent version that supports the latest Xcode. Windows and Linux cannot run iOS simulators.
Install and Verify Xcode
Install Xcode from the Mac App Store, open it once, then run `xcode-select --install` and `xcodebuild -version` to confirm the tools are ready.
Check iOS Simulators
In Xcode, confirm at least one iOS simulator runtime is installed and that an iPhone simulator appears in Window > Devices and Simulators.
Step 6: Appium Server and Drivers (UiAutomator2 & XCUITest)
Install Appium 2.x
Install Node.js LTS, then run `npm install -g appium`. Confirm `appium -v` shows a 2.x version. Appium 1.x is deprecated.
Add Platform Drivers
Use `appium driver install uiautomator2` and `appium driver install xcuitest` to enable Android and iOS automation. Check them with `appium driver list`.
How Drivers Work
UiAutomator2 and XCUITest drivers use platform test frameworks under the hood. Your Java tests talk to Appium, which translates commands for each OS.
Step 7: Create a Skeleton Maven Project for Mobile Tests
Now that the tooling is installed, create a minimal Java project that can talk to Appium for Android and iOS.
1. Generate a Maven project (quickstart archetype)
From a terminal in your workspace folder:
```bash
mvn archetype:generate \
-DgroupId=com.example.mobiletests \
-DartifactId=mobile-test-demo \
-DarchetypeArtifactId=maven-archetype-quickstart \
-DinteractiveMode=false
```
This creates a simple Java project under `mobile-test-demo`.
2. Update `pom.xml` with test and Appium dependencies
Open `pom.xml` and adjust it to something like this (versions are examples that are current as of 2026; always check Maven Central for the latest patch versions):
Step 8: Add a Simple Android Test Using UiAutomator2
Next, add a basic Android test that connects to the Appium server and a running emulator using the UiAutomator2 driver.
1. Create a base Android test class
In `src/test/java/com/example/mobiletests/`, create `AndroidSampleTest.java` with the following content. This assumes:
- Appium server is running on `http://127.0.0.1:4723`.
- An Android emulator is running and visible via `adb devices`.
This test just opens the Android settings app (or any simple app) to verify connectivity.
Step 9: Sketch an iOS Test Using XCUITest (macOS Only)
If you are on macOS with Xcode installed, you can add a similar skeleton for iOS using the XCUITest driver.
1. Create `IosSampleTest.java`
In the same `src/test/java/com/example/mobiletests/` folder, add the following. Update the `platformVersion` and `deviceName` to match an installed simulator (for example, iOS 17 on iPhone 15).
Step 10: Dry Run Checklist – Does Everything Talk to Everything?
Use this checklist as a thought exercise and, if possible, actually run the commands.
Android connectivity checklist
- Can your OS find Java 17?
- Run: `java -version` and confirm it is 17.
- Can Maven build the project?
- From the project root: `mvn test -Dtest=AndroidSampleTest`.
- Is the Android emulator visible?
- Start the AVD.
- Run: `adb devices` and check it appears as `device`.
- Is Appium server running?
- In a separate terminal: `appium`.
- Watch the logs when you run `mvn test`.
If all four work, you have a working Android test loop.
iOS connectivity checklist (macOS)
- Xcode and simulators:
- Run: `xcodebuild -version`.
- Open Xcode and confirm an iPhone simulator exists.
- Appium XCUITest driver:
- Run: `appium driver list` and confirm `xcuitest` is installed.
- Test run:
- Start Appium.
- Run: `mvn test -Dtest=IosSampleTest`.
Reflection exercise
- If a test fails to start a session, which layer is most likely at fault?
- JDK and build tool
- Platform SDK (Android SDK or Xcode)
- Appium server and drivers
- Capabilities in your test code
Try to map each error message you see (if any) back to one of these layers.
Step 11: Quick Knowledge Check
Test your understanding of how the pieces fit together.
Which statement best describes how Appium, UiAutomator2, and XCUITest work together with your Java tests?
- Your Java tests call UiAutomator2 and XCUITest APIs directly; Appium is only used to start devices.
- Your Java tests use the Appium Java client to send WebDriver commands to Appium, which then uses UiAutomator2 for Android and XCUITest for iOS.
- Appium replaces the need for Android SDK and Xcode, so UiAutomator2 and XCUITest are no longer required.
Show Answer
Answer: B) Your Java tests use the Appium Java client to send WebDriver commands to Appium, which then uses UiAutomator2 for Android and XCUITest for iOS.
In a modern Appium 2.x setup, your Java tests talk to Appium via the Java client using WebDriver commands. Appium then delegates to platform-specific drivers: UiAutomator2 on Android and XCUITest on iOS, which in turn rely on the Android SDK and Xcode.
Step 12: Flashcard Review – Key Terms
Flip through these cards to reinforce the core concepts from this module.
- JDK 17
- A long-term support Java Development Kit version widely used in 2026. Recommended baseline for Appium-based Java mobile testing projects.
- Android SDK and AVD
- Android SDK provides tools like adb and platform libraries. AVDs are Android Virtual Devices (emulators) that you run tests against.
- Xcode and iOS Simulator
- Xcode is Apple's IDE and toolchain that includes iOS SDKs and simulator runtimes. Required for running iOS simulators and XCUITest-based automation on macOS.
- Appium 2.x
- A cross-platform automation server that receives WebDriver commands and delegates them to installed drivers such as UiAutomator2 (Android) and XCUITest (iOS).
- UiAutomator2 Driver
- Appium driver that uses Android's UiAutomator2 testing framework under the hood to interact with UI elements on Android devices and emulators.
- XCUITest Driver
- Appium driver that uses Apple's XCUITest framework and WebDriverAgent app to automate iOS simulators and real devices.
- DesiredCapabilities (Capabilities)
- A set of key-value pairs sent from your test to Appium to describe the target platform, device, app, and automation settings for a session.
- Maven Project Structure
- Standard layout with `src/main/java` for production code and `src/test/java` for tests, managed by a pom.xml that defines dependencies and plugins.
Key Terms
- AVD
- Android Virtual Device; an emulator configuration that simulates a real Android device.
- JDK
- Java Development Kit; includes the Java runtime and compiler needed to build and run Java code.
- Maven
- A Java build and dependency management tool that uses a pom.xml file to define project configuration.
- Xcode
- Apple's IDE and toolchain for building apps on Apple platforms, including iOS, macOS, watchOS, and tvOS.
- Appium
- An open-source automation framework that uses the WebDriver protocol to drive native, hybrid, and mobile web apps.
- XCUITest
- Apple's UI testing framework for iOS and other Apple platforms; Appium's XCUITest driver relies on it.
- Android SDK
- Software Development Kit for Android, including tools like adb, platform libraries, and build tools.
- Capabilities
- Configuration parameters sent from a test client to Appium to describe the desired test session (platform, device, app, etc.).
- UiAutomator2
- An Android UI testing framework; Appium's UiAutomator2 driver uses it to interact with Android app UIs.
- iOS Simulator
- A virtual device environment provided by Xcode to run and test iOS apps without real hardware.