Skip to content

Instantly share code, notes, and snippets.

@tcamin
tcamin / AppDelegate.swift
Last active June 29, 2016 09:28
SBTUITestTunnel Setup
import UIKit
import SBTUITestTunnel
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
override class func initialize() {
SBTUITestTunnelServer.takeOff()
super.initialize()
@tcamin
tcamin / Podfile
Created June 29, 2016 09:23
SBTUITestTunnel Setup
use_frameworks!
target 'APP_TARGET' do
pod 'SBTUITestTunnel/Server'
end
target 'UITESTS_TARGET' do
pod 'SBTUITestTunnel/Client'
end
@tcamin
tcamin / SetupTest.swift
Last active June 29, 2016 12:56
SBTUITestTunnel XCTestCase Setup
import XCTest
import SBTUITestTunnel
class TestTunnelDemoUITests: XCTestCase {
var app: SBTUITunneledApplication!
override func setUp() {
super.setUp()
continueAfterFailure = true
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!)
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)
}
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
}
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 {
func testCustomBlock() {
let someObjectToInject: AnyObject = ...
// this will invoke the code of block in ViewController.swift
app.performCustomCommandNamed("myCustomCommandKey", object: someObjectToInject)
}
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()
}
}
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 {