Giter Club home page Giter Club logo

lunch's Introduction

Build Status

Lunch

Lunch is helper of UI Test with Swift.

Requirements

  • Swift 4.0 or later
  • iOS 9 or later

Installation

Carthage

  • Insert github "fromkk/Lunch" to your Cartfile .
  • Run carthage update
  • Link your app with Lunch.framework in Carthage/Build
  • Link your UI test target with LunchTest.framework in Carthage/Build

Usage

In App target adopt protocol Creatable.

import Lunch

struct Creator: Creatable {
    func create<T>(_ identifier: String, userInfo: [AnyHashable : Any]?) -> T? {
        switch identifier {
        case "LunchViewController":
            return self.lunchViewController() as? T
        default:
            return nil
        }
    }
}

extension Creatable {
    func lunchViewController() -> LunchViewController {
        let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
        return storyboard.instantiateInitialViewController() as! LunchViewController
    }
}
// AppDelegate.swift
import Lunch

let creator = Creator()
let rootViewController: UIViewController
#if DEBUG
if let viewController: UIViewController = Launcher(with: creator).launch() {
    rootViewController = viewController
} else {
    rootViewController = creator.lunchViewController()
}
#else
rootViewController = creator.lunchViewController()
#endif
window?.rootViewController = rootViewController

NOTE: If you want change rootViewController after Run Xcode, set LAUNCH_VIEW_CONTROLLER key and viewController name to value in Environment Variables of your scheme.

In UI Test target.

1 Add component and adopt protocol PageObjectsRepresentable.

import XCTest
import LunchTest

struct LunchViewControllerPage: PageObjectsRepresentable {
    var app: XCUIApplication
    init(app: XCUIApplication) {
        self.app = app
    }

    var lunchLabel: XCUIElement {
        return self.app.staticTexts["lunchLabel"]
    }
}

2 Add your tests and adopt protocol ViewControllerTestable

import XCTest
import LunchTest

class LunchViewControllerTests: XCTestCase, ViewControllerTestable {

    var viewControllerName: String {
        return "LunchViewController"
    }

    override func setUp() {
        super.setUp()

        continueAfterFailure = false
    }

    func testLunchLabel() {
        let launcher = Launcher(targetViewController: self)
        let app = launcher.launch()

        let page = LunchViewControllerPage(app: app)
        XCTAssertTrue(page.lunchLabel.exists)
        XCTAssertEqual(page.lunchLabel.label, "Lunch")
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.