This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import SBTUITestTunnel | |
@UIApplicationMain | |
class AppDelegate: UIResponder, UIApplicationDelegate { | |
var window: UIWindow? | |
override class func initialize() { | |
SBTUITestTunnelServer.takeOff() | |
super.initialize() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use_frameworks! | |
target 'APP_TARGET' do | |
pod 'SBTUITestTunnel/Server' | |
end | |
target 'UITESTS_TARGET' do | |
pod 'SBTUITestTunnel/Client' | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import XCTest | |
import SBTUITestTunnel | |
class TestTunnelDemoUITests: XCTestCase { | |
var app: SBTUITunneledApplication! | |
override func setUp() { | |
super.setUp() | |
continueAfterFailure = true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func testStubbing() { | |
// setup your stub | |
let stubId = app.stubRequestsWithRegex("(.*)apple(.*)", returnJsonDictionary: ["key": "value"], returnCode: 200, responseTime: SBTUITunnelStubsDownloadSpeed3G) | |
// execute your test here. Expect requests to `(.*)apple(.*)` to return a JSON | |
... | |
// you can optionally remove the stub | |
app.stubRequestsRemoveWithId(stubId!) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func testNSUserDefaultsAndKeychain() { | |
app.userDefaultsSetObject(0, forKey: "view_count") | |
// interact with UI | |
app.buttons["Button"].tap() | |
let counter = app.userDefaultsObjectForKey("view_count")?.integerValue! | |
XCTAssert(counter == 1) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func testFilesystem() { | |
let pathToFile = "MyFakeDB.sqlite" | |
app.uploadItemAtPath(pathToFile, toPath: "/db/db.sqlite", relativeTo: .DocumentDirectory) | |
// interact with UI | |
let uploadData = app.downloadItemFromPath("/db/db.sqlite", relativeTo: .DocumentDirectory) | |
// check that file was modified as expected | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func testRequestMonitor() { | |
// listen to all calls made to `(.*)apple(.*)` | |
app.monitorRequestsWithRegex("(.*)myserver(.*)") | |
// interact with UI | |
// check that there's everything you're expecting | |
let requests: [SBTMonitoredNetworkRequest] = app.monitoredRequestsFlushAll() | |
for request in requests { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func testCustomBlock() { | |
let someObjectToInject: AnyObject = ... | |
// this will invoke the code of block in ViewController.swift | |
app.performCustomCommandNamed("myCustomCommandKey", object: someObjectToInject) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
return dataSource.count + moreItemsToLoad ? 1 : 0 | |
} | |
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) { | |
if cell is TableViewCellLoadingCell { | |
fetchNewItems() | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ViewController: UITableViewController { | |
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
return 20 | |
} | |
override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) { | |
print("will display cell \(indexPath)") | |
} | |
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { |
OlderNewer