Skip to content

Instantly share code, notes, and snippets.

import KIF
class HomeTests : KIFTestCase {
// test method name MUST have the prefix `test`
// for example: testA, testB, testLogin, ect...
func testHomeScreen() {
visitHomeScreen()
tapOn("button")
expectToSee("Some random label")
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
target 'SetupTestingForiOSProject' do
# Comment this line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for SetupTestingForiOSProject
target 'SetupTestingForiOSProjectTests' do
platform :ios, '9.0'
target 'MyAwesomeProject' do
use_frameworks!
target 'MyAwesomeProjectTests' do
inherit! :search_paths
pod 'Quick'
pod 'Nimble'
end
platform :ios, '9.0'
target 'MyAwesomeProject' do
target 'MyAwesomeProjectTests' do
inherit! :search_paths
pod 'Specta'
pod 'Expecta'
end
end

Match

. : match any single character
* : match 0 or more times
\+ : match 1 or more times
\= : match 0 or 1 time (match optional)
\( : open group
\) : close group

Count

import XCTest
class MyNativeTests: XCTestCase {
override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
}
override func tearDown() {
import XCTest
class MyNativeTests: XCTestCase {
func testSomething() {
}
}
import Foundation
class Gun: NSObject {
var bullets = 0
init(bullets: Int) {
self.bullets = bullets
}
import XCTest
@testable import MyAwesomeProject
class MyNativeTests: XCTestCase {
func testGunCanShootIfItHasBullets() {
// 1. Setup: create a gun with 1 bullet
let gun = Gun(bullets: 1)
// 2. Execution: shoot
gun.shoot()

describe Gun

  • describe shoot
    • when has bullets
      • when is unlocked
        • it can shoot
      • when is locked
        • it cannot shoot
    • when has no bullet
      • it cannot shoot
  • describe lock