Latest 1.0.2
Homepage https://github.com/CrossWaterBridge/Mole
License MIT
Platforms ios 8.0, requires ARC
Dependencies Swifter

Pod Version
Pod License
Pod Platform

Xcode’s UI testing is black-box by design. This works around that.

Installation

Install with CocoaPods by adding the following to your Podfile:

use_frameworks!

pod 'Mole'

Be sure to add Mole to both your app and UI test targets. Then run:

pod install

Usage

Create a server class in your app target. Register methods you want your UI test target to be able to call:

import Mole

class AppServer {
    private let server = MoleServer()

    init() {
        server["upgraded"] = { _ in
            return ProductController.sharedController.upgraded
        }

        server["setUpgraded"] = { args in
            if let args = args as? [String: Bool], upgraded = args["upgraded"] {
                ProductController.sharedController.upgraded = upgraded
            }

            return nil
        }
    }
}

Then create a proxy class in your UI test target, with proxy methods that correspond to the methods in your server class:

import Mole

class AppProxy {
    private let client = MoleClient()

    func upgraded() -> Bool {
        return client.invokeMethod("upgraded") as? Bool ?? false
    }

    func setUpgraded(upgraded: Bool) {
        client.invokeMethod("setUpgraded", parameters: ["upgraded": upgraded])
    }
}

Now you can call methods on your proxy class from your UI tests:

class Tests: XCTestCase {
    func testUpgrade() {
        let appProxy = AppProxy()
        appProxy.setUpgraded(true)
        XCTAssertTrue(appProxy.upgraded())
    }
}

License

Mole is released under the MIT license. See LICENSE for details.

Latest podspec

{
    "name": "Mole",
    "version": "1.0.2",
    "summary": "Xcodeu2019s UI testing is black-box by design. This works around that.",
    "authors": "Hilton Campbell",
    "homepage": "https://github.com/CrossWaterBridge/Mole",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "source": {
        "git": "https://github.com/CrossWaterBridge/Mole.git",
        "tag": "1.0.2"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "Mole/*.swift",
    "requires_arc": true,
    "dependencies": {
        "Swifter": [
            "1.1.4"
        ]
    }
}

Pin It on Pinterest

Share This