Swift Testing and Architecture

Swift Testing and Architecture

8e7d17f63cb19895a31b4ba6a976e781?s=128

Danielle Tomlinson

September 11, 2015
Tweet

Transcript

  1. Testing @DanToml

  2. What? Test noun: A procedure intended to establish the quality,

    performance, or reliability of something, especially before it is taken into widespread use.
  3. Why?

  4. Tools

  5. XCTest // Contrived example test for a mythical add function

    func test_can_add_two_numbers() { // arrange let firstNumber = 1 let secondNumber = 1 let expectedResult = 2 // act let ! = add(firstNumber, secondNumber) // assert XCTAssertEqual(!, expectedResult) }
  6. FBSnapshotTestCase // https://github.com/facebook/ios-snapshot-test-case func test_taylor_swift_view_displays_correct_image() { let viewModel = TaylorSwiftImageViewModel.testViewModel()

    let sut = TaylorSwiftImageView(viewModel: viewModel) FBSnapshotVerifyView(sut) }
  7. OHHTTPStubs OHHTTPStubs.stubRequestsPassingTest({$0.URL!.host == "mywebservice.com"}) { _ in // Stub it

    with our "wsresponse.json" stub file (which is in same bundle as self) let fixture = OHPathForFile("wsresponse.json", self.dynamicType) return OHHTTPStubsResponse(fileAtPath: fixture!, statusCode: 200, headers: ["Content-Type":"application/json"]) }
  8. UI Testing

  9. Code Coverage

  10. Architecture

  11. Modal View Controller

  12. Massive View Controller

  13. Breaking it out

  14. MVVM Model-View-ViewModel

  15. Dependency Injection & Composability

  16. Clarity

  17. Use what works for you

  18. Lets talk about Testing

  19. Singletons

  20. View Models

  21. Views

  22. View Controllers

  23. Non-View Controllers

  24. Resources 4 I'll be releasing a sample project on GitHub

    at some point in the next week or two. 4 ObjC.io VIPER: http://bit.ly/1Ht1V6Y 4 ObjC.io MVVM: http://bit.ly/1UNLXJf 4 ObjC.io Lightweight View Controllers: http://bit.ly/ 1K1wAtw 4 WWDC Session 229
  25. Questions? Find me on Twitter: @dantoml