Running XCTest on Android
This guide explains how to run XCTest on Android using `scd`.
Introduction
XCTest is Apple's standard testing framework for Swift and Objective-C projects.
It provides tools for writing and running unit tests, performance tests, and UI tests.
In Swift projects, XCTest is most commonly used together with Swift Package Manager (SPM).
Test cases are typically located in the Tests/ directory and use the XCTestCase class to define test methods and assertions.
While XCTest is traditionally used on Apple platforms such as macOS and iOS, it can also be executed on Android when using a compatible Swift toolchain.
This guide shows how to build and run XCTest-based Swift packages on Android using scd.
Prerequisites
- A Swift Package Manager (SPM) project that contains XCTest tests
- An Android emulator or a connected physical device
Install scd
Download and install the latest scd.
Verify installation:
scd --versionRun XCTest on Android
From the project root, run:
scd test --platform android-arm64-v8a --device <avd_or_running_device_name>If only one device or emulator is available, the --device parameter can be omitted:
scd test --platform android-arm64-v8aThe test bundle will be built, deployed to the selected Android target, and executed. Test results are printed to the terminal.
Running Tests from Any SPM Project
You can run XCTest on Android for any open-source Swift package that:
- Uses Swift Package Manager
- Contains XCTest-based tests
The process is always the same:
git clone <repository-url>
cd <repository-folder>
scd test --platform android-arm64-v8aExample: Running Tests from swift-algorithms
As an example, you can use Apple’s open-source swift-algorithms package.
Clone the repository:
git clone https://github.com/apple/swift-algorithms.git
cd swift-algorithmsRun the tests on Android:
scd test --platform android-arm64-v8aThe XCTest suite will be compiled into an Android test APK, installed on the selected device or emulator, and executed.
Example terminal output:
...
02-26 16:17:09.168 4258 4299 D SwiftTestFoundation: Test Suite 'UniqueTests' started at 2026-02-26 16:17:09.169
02-26 16:17:09.168 4258 4299 D SwiftTestFoundation: Test Case 'UniqueTests.testLazyUniqueOn' started at 2026-02-26 16:17:09.169
02-26 16:17:09.169 4258 4299 D SwiftTestFoundation: Test Case 'UniqueTests.testLazyUniqueOn' passed (0.0 seconds)
02-26 16:17:09.169 4258 4299 D SwiftTestFoundation: Test Case 'UniqueTests.testUnique' started at 2026-02-26 16:17:09.169
02-26 16:17:09.169 4258 4299 D SwiftTestFoundation: Test Case 'UniqueTests.testUnique' passed (0.0 seconds)
02-26 16:17:09.169 4258 4299 D SwiftTestFoundation: Test Case 'UniqueTests.testUniqueOn' started at 2026-02-26 16:17:09.170
02-26 16:17:09.170 4258 4299 D SwiftTestFoundation: Test Case 'UniqueTests.testUniqueOn' passed (0.0 seconds)
02-26 16:17:09.170 4258 4299 D SwiftTestFoundation: Test Suite 'UniqueTests' passed at 2026-02-26 16:17:09.170
02-26 16:17:09.170 4258 4299 D SwiftTestFoundation: Executed 3 tests, with 0 failures (0 unexpected) in 0.001 (0.001) seconds
02-26 16:17:09.170 4258 4299 D SwiftTestFoundation: Test Suite 'WindowsTests' started at 2026-02-26 16:17:09.170
02-26 16:17:09.170 4258 4299 D SwiftTestFoundation: Test Case 'WindowsTests.testWindowsCount' started at 2026-02-26 16:17:09.170
02-26 16:17:09.170 4258 4299 D SwiftTestFoundation: Test Case 'WindowsTests.testWindowsCount' passed (0.0 seconds)
02-26 16:17:09.170 4258 4299 D SwiftTestFoundation: Test Case 'WindowsTests.testWindowsIndexAfterAndBefore' started at 2026-02-26 16:17:09.170
02-26 16:17:09.170 4258 4299 D SwiftTestFoundation: Test Case 'WindowsTests.testWindowsIndexAfterAndBefore' passed (0.0 seconds)
02-26 16:17:09.170 4258 4299 D SwiftTestFoundation: Test Case 'WindowsTests.testWindowsIndexTraversals' started at 2026-02-26 16:17:09.170
02-26 16:17:09.173 4258 4299 D SwiftTestFoundation: Test Case 'WindowsTests.testWindowsIndexTraversals' passed (0.003 seconds)
02-26 16:17:09.173 4258 4299 D SwiftTestFoundation: Test Case 'WindowsTests.testWindowsLazy' started at 2026-02-26 16:17:09.173
02-26 16:17:09.173 4258 4299 D SwiftTestFoundation: Test Case 'WindowsTests.testWindowsLazy' passed (0.0 seconds)
02-26 16:17:09.173 4258 4299 D SwiftTestFoundation: Test Case 'WindowsTests.testWindowsOfInt' started at 2026-02-26 16:17:09.173
02-26 16:17:09.173 4258 4299 D SwiftTestFoundation: Test Case 'WindowsTests.testWindowsOfInt' passed (0.0 seconds)
02-26 16:17:09.173 4258 4299 D SwiftTestFoundation: Test Case 'WindowsTests.testWindowsOfRange' started at 2026-02-26 16:17:09.173
02-26 16:17:09.173 4258 4299 D SwiftTestFoundation: Test Case 'WindowsTests.testWindowsOfRange' passed (0.0 seconds)
02-26 16:17:09.173 4258 4299 D SwiftTestFoundation: Test Case 'WindowsTests.testWindowsOfString' started at 2026-02-26 16:17:09.174
02-26 16:17:09.173 4258 4299 D SwiftTestFoundation: Test Case 'WindowsTests.testWindowsOfString' passed (0.0 seconds)
02-26 16:17:09.173 4258 4299 D SwiftTestFoundation: Test Case 'WindowsTests.testWindowsSecondAndLast' started at 2026-02-26 16:17:09.174
02-26 16:17:09.174 4258 4299 D SwiftTestFoundation: Test Case 'WindowsTests.testWindowsSecondAndLast' passed (0.0 seconds)
02-26 16:17:09.174 4258 4299 D SwiftTestFoundation: Test Suite 'WindowsTests' passed at 2026-02-26 16:17:09.174
02-26 16:17:09.174 4258 4299 D SwiftTestFoundation: Executed 8 tests, with 0 failures (0 unexpected) in 0.004 (0.004) seconds
02-26 16:17:09.174 4258 4299 D SwiftTestFoundation: Test Suite 'swift.xctest' passed at 2026-02-26 16:17:09.174
02-26 16:17:09.174 4258 4299 D SwiftTestFoundation: Executed 224 tests, with 0 failures (0 unexpected) in 2.917 (2.917) seconds
02-26 16:17:09.174 4258 4299 D SwiftTestFoundation: Test Suite 'All tests' passed at 2026-02-26 16:17:09.174
02-26 16:17:09.174 4258 4299 D SwiftTestFoundation: Executed 224 tests, with 0 failures (0 unexpected) in 2.917 (2.917) seconds
02-26 16:17:09.174 4258 4299 D SwiftTestFoundation: XCTMain finished
02-26 16:17:10.180 4258 4258 I wift_algorithms: System.exit called, status: 0
02-26 16:17:10.180 4258 4258 I AndroidRuntime: VM exiting with result code 0, cleanup skipped.