Some of the most commonly used assertions

  • XCTAssert(expression, string)
  • XCTAssertEqual(expresion1, expr2, String)
  • XCTAssertEqualWithAccuracy(exp1, exp2, accuracy, string)
  • XCTAssertFalse()
  • XCTAssertGreaterThan()
  • XCTAssertGreaterThanOrEqual()
  • XCTAssertNil()
  • XCTAssertNotEqual()
  • XCTAssertNotEqualWithAccuracy()
  • XCTAssertNotNil()

Common functions in XCTest class:

// Is going to run before every test
 override func setUp() {
        calc = TipCalculator()

// runs after evert test case in the file is ran.    
override func tearDown() {

Performance tests:

For easy and simple performance test use

   // fn to test. after the first run you can set the baseline.

*** Note: This is only for simple testing. For a full performance and IO tests use XCODE and instruments ***

Mocks and Stubs:

  • Dummy = objects passed around are never actually used

  • Fake = objects actually have some implementation but not for production use.

  • Stubs = Provide canned answers to calls made during the test. Usually does not respond to anything outside of what's programmed in for test. eg: Email gateway stub that remembers messages it 'sent'

  • Mocks = objects pre-programmed with expectations which form a spec of the call they are expected to receive.