Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fromkk/lunch
Lunch is helper of UI Test with Swift.
https://github.com/fromkk/lunch
ios swift swift-4 ui-testing ui-tests
Last synced: about 5 hours ago
JSON representation
Lunch is helper of UI Test with Swift.
- Host: GitHub
- URL: https://github.com/fromkk/lunch
- Owner: fromkk
- License: mit
- Created: 2017-08-11T12:06:58.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-07-18T23:09:10.000Z (about 5 years ago)
- Last Synced: 2024-09-24T20:38:02.749Z (about 10 hours ago)
- Topics: ios, swift, swift-4, ui-testing, ui-tests
- Language: Swift
- Size: 58.6 KB
- Stars: 55
- Watchers: 5
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
[![Build Status](https://app.bitrise.io/app/f867ecf1d4e7e2b0/status.svg?token=ojd97UYMck4Wj2LREpRTiQ)](https://app.bitrise.io/app/f867ecf1d4e7e2b0)
# 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`.
```swift
import Lunchstruct Creator: Creatable {
func create(_ 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
}
}```
```swift
// AppDelegate.swift
import Lunchlet 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`.
```swift
import XCTest
import LunchTeststruct 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`
```swift
import XCTest
import LunchTestclass 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")
}
}
```