How to test with Mock Device Kit on iOS

Updated: Nov 13, 2026

Overview

Use this guide when your iOS project already integrates the Wearables Device Access Toolkit and you need to test without physical glasses.

Use this page with AI

Your AI coding tool works best here with the Device Access Toolkit iOS plugin installed. Its mockdevice-testing skill covers Mock Device Kit setup, mock camera feeds, and test patterns for iOS.
Copy this prompt into your AI coding tool to add iOS Mock Device Kit tests:

Use https://wearables.developer.meta.com/docs/develop/dat/testing-mdk-ios/, then use the Wearables MCP endpoint https://mcp.developer.meta.com/wearables to call search_dat_docs for current iOS Mock Device Kit test guidance. If the Device Access Toolkit iOS plugin is not installed, install it from https://github.com/meta/meta-wearables-dat-ios and use its mockdevice-testing skill. Inspect my iOS tests first, then add the smallest XCTest or XCUITest coverage for mock device pairing, permission setup, camera feed or captured photo behavior, and cleanup. Keep the test deterministic and run the relevant local test command.

Set up Mock Device Kit in XCTest

Create a reusable base test class that enables Mock Device Kit before each test and disables it afterward.
import MWDATCore
import MWDATMockDevice
import XCTest

@MainActor
class MockDeviceKitTestCase: XCTestCase {
    override func setUp() async throws {
        try await super.setUp()
        try? Wearables.configure()
        MockDeviceKit.shared.enable()
    }

    override func tearDown() async throws {
        await MockDeviceKit.shared.disable()
        try await super.tearDown()
    }
}

Configure camera feeds for streaming tests

Mock camera feeds let you verify streaming and capture workflows without video hardware.

Provide a mock video feed

let device = try MockDeviceKit.shared.pairGlasses(model: .rayBanMeta)
let camera = device.services.camera
camera.setCameraFeed(fileURL: videoURL)

Provide a captured photo

let device = try MockDeviceKit.shared.pairGlasses(model: .rayBanMeta)
let camera = device.services.camera
camera.setCapturedImage(fileURL: imageURL)

MockDevice test server for XCUITest

The MockDevice test server enables UI automation testing by allowing XCUITest processes to control mock devices at runtime via HTTP. This eliminates the need to hardcode mock device setup in your app, enabling dynamic test scenarios where each test can configure its own device state.
This approach enables UI automation without physical hardware (run XCUITests on CI simulators), dynamic test scenarios (each test pairs different devices and configures unique camera feeds), full flow testing (registration, pairing, streaming, photo capture), deterministic testing (control exact device state to test edge cases), and parallel test execution (each test manages its own mock device independently).
Note: For more examples of how to leverage the MockDevice Test Server to test your apps, see the Camera Access sample code at ExternalSampleApps/CameraAccess/CameraAccessUITests/.

Architecture

The test server runs in your app process and listens on localhost. The XCUITest client connects via HTTP to control mock devices. The server writes its port to a temp file that the client reads to discover the connection details. Both processes share the same /tmp directory on the simulator.
┌─────────────────────────────────────┐                         ┌──────────────────────────────────┐
│         App Process (DEBUG)         │     HTTP (localhost)    │     XCUITest Process             │
│                                     │                         │                                  │
│  MockDeviceKit                      │   pair, power, wear,    │  MockDeviceTestClient            │
│   └─ startTestServer()              │   fold, camera feed,    │                                  │
│                                     │   state queries, ...    │  Port discovery:                 │
│                                     │                         │   reads port from temp file      │
│                                     │                         │   written by server on start     │
│                                     │◄────────────────────────│                                  │
└─────────────────────────────────────┘                         └──────────────────────────────────┘

Server setup (app process)

Start the test server when the app launches with a --ui-testing flag. The server should only be enabled in DEBUG builds.
import MWDATMockDevice

if ProcessInfo.processInfo.arguments.contains("--ui-testing") {
    MockDeviceKit.shared.enable(config: MockDeviceKitConfig(initiallyRegistered: false))

    let portFilePath = ProcessInfo.processInfo.environment["MWDAT_TEST_SERVER_PORT_FILE"]
    Task {
        try await MockDeviceKit.shared.startTestServer(portFilePath: portFilePath)
        // Server is now listening — tests drive mock device setup via HTTP
    }
}

Client setup (XCUITest process)

Link MWDATMockDeviceTestClient in your UI test target. The client reads the port from the temp file.
import MWDATMockDeviceTestClient
import XCTest

@MainActor
final class MyUITests: XCTestCase {
    var portFilePath: String {
        NSTemporaryDirectory() + "mwdat_test_server_port.txt"
    }
    private let app = XCUIApplication()
    private var mockClient: MockDeviceTestClient!
    private var deviceId: String?

    override func setUp() async throws {
        // Remove any stale port file from a previous run
        try? FileManager.default.removeItem(atPath: portFilePath)

        app.launchArguments = ["--ui-testing"]
        app.launchEnvironment["MWDAT_TEST_SERVER_PORT_FILE"] = portFilePath
        app.launch()

        // Initialize the client after launch so the server has time to write the port file
        mockClient = MockDeviceTestClient(portFilePath: portFilePath)
        let serverReachable = await mockClient.waitForServer(timeout: 10)
        XCTAssertTrue(serverReachable, "Test server should be running")
    }

    override func tearDown() async throws {
        if let deviceId {
            await mockClient.unpairDevice(deviceId: deviceId)
        }
        deviceId = nil
    }

    func testStreaming() async {
        // Pair a device — pairDevice() powers it on and dons it automatically
        guard let id = await mockClient.pairDevice() else {
            XCTFail("Failed to pair mock device")
            return
        }
        deviceId = id

        // Configure camera resources for this device
        await mockClient.setCameraFeed(deviceId: id, resourceName: "plant", ext: "mp4")
        await mockClient.setCapturedImage(deviceId: id, resourceName: "plant", ext: "png")

        // Device is now paired, powered on, and donned
        let startButton = app.buttons["Start streaming"]
        XCTAssertTrue(startButton.waitForExistence(timeout: 15))

        // Control device state mid-test
        await mockClient.doff(deviceId: id)   // wear state only; the device stays active
        await mockClient.don(deviceId: id)    // worn again
        await mockClient.fold(deviceId: id)   // hinges close; ends any active session and stream
        await mockClient.unfold(deviceId: id) // hinges open

        // Query device state
        let state = await mockClient.getDeviceState()
        XCTAssertEqual(state?["pairedDeviceCount"] as? Int, 1)
    }
}

Available client methods

Every client method is async. Call it with await from an async test, setUp, or tearDown method.
MethodDescription
pairDevice()
Pairs a mock Ray-Ban Meta device, powers it on, and simulates wearing it. Returns the ID of the paired device, or nil if pairing fails.
unpairDevice(deviceId:)
Unpairs the specified mock device
powerOn(deviceId:) / powerOff(deviceId:)
Controls device power state
don(deviceId:) / doff(deviceId:)
Simulates wearing / removing the device
fold(deviceId:) / unfold(deviceId:)
Simulates folding / unfolding the glasses
captouchTap(deviceId:)
Simulates a single touchpad tap (toggles pause/resume)
captouchTapAndHold(deviceId:)
Simulates a touchpad tap and hold (stops active session)
setCameraFeed(deviceId:resourceName:ext:)
Sets the camera feed video resource from the app’s bundle
setCapturedImage(deviceId:resourceName:ext:)
Sets the captured image resource from the app’s bundle
getDeviceState()
Returns {"pairedDeviceCount": Int, "deviceIds": [String]}
healthCheck()
Checks if the server is reachable
waitForServer(timeout:)
Polls until the server responds or timeout expires
The test server runs in your app, so it looks up resourceName and ext in the app’s bundle. Add these files to the app target, not to the UI test target.

Swift Package Manager setup

Add MWDATMockDeviceTestClient as a dependency of your UI test target. The client has no dependency on MWDATMockDevice — it communicates purely over HTTP.