Upgrade to Pro — share decks privately, control downloads, hide ads and more …

TDD in iOS

TDD in iOS

German presentation about TDD in iOS

Dominik Hauser

December 04, 2019
Tweet

Other Decks in Programming

Transcript

  1. The quality and performance achieved could not have been done

    without the use of unit testing. — Bill Bumgarner (bbum), über Core Data 1.0
  2. Vorteile1 · Refaktorierbarkeit · Schnelles Feedback · Gedankenstütze · Doppelte

    Buchführung · Regressionsschutz 1 Von (subjektiv) wichtig nach unwichtig
  3. Planning/Feedback Loops Release Plan Code Iteration Plan Acceptance Test Stand

    Up Meeting Pair Negotiation Unit Test Pair Programming Months Weeks Days One day Hours Minutes Seconds DonWells (CC BY-SA 3.0)
  4. class TableViewCell: UITableViewCell { let label = UILabel() override init(style:

    UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) addSubview(label) } }
  5. class TableViewCell: UITableViewCell { let label = UILabel() override init(style:

    UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) addSubview(label) } }
  6. "Was soll denn da kaputt gehen?" 1. That can’t happen.

    2. That doesn’t happen on my machine. 3. That shouldn’t happen. 4. Why does that happen? 5. Oh, I see. 6. How did that ever work?2 2 Mike W. Cremer
  7. RELEASE 1.0 TESTS RELEASE 1.1 Login Login Tests User User

    Tests Logout Logout Tests Password reset Password Tests Blocking of users Blocking tests ... ...
  8. RELEASE 1.0 RELEASE 1.1 TESTS Login Login Tests User User

    Tests Logout Logout Tests Password reset Password Tests Blocking of users Blocking tests ... ...
  9. func test_loadingView_registersCell() { // when sut.loadViewIfNeeded() // then let cell

    = sut.tableView.dequeueReusableCell( withIdentifier: "Cell", for: IndexPath(row: 0, section: 0)) XCTAssertNotNil(cell) XCTAssertTrue(cell is Cell) }
  10. func test_showNext_pushesViewController() { // given let navControllerMock = NavigationControllerMock( rootViewController:

    sut) let user = User(name: "Foobar") // when sut.showNext(with: user) // then let detailController = navControllerMock.lastPushedVC as! DetailViewController XCTAssertEqual(detailController.user, user) }
  11. View laden func test_foo() { // given ... // when

    view loads sut.loadViewIfNeeded() // then ... }
  12. viewWill/DidAppear func test_foo() { // given ... // when view

    appears sut.beginAppearanceTransition(true, animated: false) sut.endAppearanceTransition() // then ... }
  13. Modal presentation func test_presentationOfViewController() { // given let window =

    UIWindow(frame: CGRect(x: 0, y: 0, width: 300, height: 300)) window.rootViewController = sut window.makeKeyAndVisible() // when sut.showNext() // then XCTAssertTrue(sut.presentedViewController is DetailViewController) }