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

BDD Bialystok/Wroclaw

BDD Bialystok/Wroclaw

Presentation on BDD, architecture and testable code I've given at Mobile Bialystok in December 2016 and at LET Swift Wroclaw in January 2017.

Pawel Dudek

January 19, 2017
Tweet

More Decks by Pawel Dudek

Other Decks in Programming

Transcript

  1. A method by which individual units of source code, sets

    of one or more program modules together with associated control data, usage procedures, and operating procedures are tested to determine if they are fit for use. --Kolawa, Adam; Huizinga, Dorota (2007) @eldudi 8
  2. A method by which individual units of source code, sets

    of one or more program modules together with associated control data, usage procedures, and operating procedures are tested to determine if they are fit for use. --Kolawa, Adam; Huizinga, Dorota (2007) @eldudi 10
  3. An app is a set of behaviors created by programmer

    and expected by user. @eldudi 12
  4. We can’t always ‘load’ all of the code of our

    app into our memory. @eldudi 14
  5. Good design » High cohesion » Low coupling » Easily

    composable » Context independent @eldudi 39
  6. Good architecture - principles » Single responsibility » Few dependencies

    » Depend on interfaces, not classes (yay POP!) @eldudi 40
  7. SOLID Homework » Goruco 2009 - SOLID Object-Oriented Design -

    Sandi Metz » MCE^3 - Software Paradigms & Patterns — Did We Get It All Wrong? - Jon Reid » MCE^3 - Jorge Ortiz » Clean Architecture - Uncle Bob @eldudi 45
  8. class DolphinSpec: QuickSpec { override func spec() { it("is friendly")

    { expect(Dolphin().isFriendly).to(beTruthy()) } it("is smart") { expect(Dolphin().isSmart).to(beTruthy()) } } } @eldudi 59
  9. describe("a dolphin") { describe("its click") { it("is loud") { let

    click = Dolphin().click() expect(click.isLoud).to(beTruthy()) } it("has a high frequency") { let click = Dolphin().click() expect(click.hasHighFrequency).to(beTruthy()) } } } @eldudi 60
  10. describe("a dolphin") { var dolphin: Dolphin! beforeEach { dolphin =

    Dolphin() } describe("its click") { var click: Click! beforeEach { click = dolphin.click() } it("is loud") { expect(click.isLoud).to(beTruthy()) } it("has a high frequency") { expect(click.hasHighFrequency).to(beTruthy()) } } } @eldudi 61
  11. describe("its click") { context("when the dolphin is not near anything

    interesting") { it("is only emitted once") { expect(dolphin!.click().count).to(equal(1)) } } context("when the dolphin is near something interesting") { beforeEach { let ship = SunkenShip() Jamaica.dolphinCove.add(ship) Jamaica.dolphinCove.add(dolphin) } it("is emitted three times") { expect(dolphin.click().count).to(equal(3)) } } } @eldudi 62
  12. BDD - recap » Tests influence your architecture » No

    such thing as untestable behavior » Think examples/behaviors, not tests » Don’t test implementation, work outside-in » Use ubiquitous language to make examples easily understandable @eldudi 64