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

iOS Unit Testing

iOS Unit Testing

Marcilio Junior

September 03, 2016
Tweet

More Decks by Marcilio Junior

Other Decks in Programming

Transcript

  1. DIGITAL DAY - SEP 3, 2016 MARCÍLIO JÚNIOR [email protected] who

    am i iOS Lead @ HE:labs iOS Instructor @ Framework Training Center Professor @ PUC Minas CocoaHeads BH Co-organizer Marcílio Júnior
  2. DIGITAL DAY - SEP 3, 2016 MARCÍLIO JÚNIOR [email protected] Why

    test • Avoid break your codebase • It’s a way to document your code • Make development faster • Reduce your fear • Improve your code quality
  3. DIGITAL DAY - SEP 3, 2016 MARCÍLIO JÚNIOR [email protected] unit

    test types • Mathematical • Pure functions • Delegation • Output
  4. DIGITAL DAY - SEP 3, 2016 MARCÍLIO JÚNIOR [email protected] unit

    test types • Mathematical • Delegation • Propagation • Output
  5. DIGITAL DAY - SEP 3, 2016 MARCÍLIO JÚNIOR [email protected] unit

    test types • Mathematical • Delegation • Output • More than one input/output
  6. DIGITAL DAY - SEP 3, 2016 MARCÍLIO JÚNIOR [email protected] (B/T)DD

    • Test-Driven Development • Behaviour-Driven Development
  7. DIGITAL DAY - SEP 3, 2016 MARCÍLIO JÚNIOR [email protected] (B/T)DD

    • Test-Driven Development • Behaviour-Driven Development let counter = Counter() let expectedCount = 1 counter.tick() XCTAssertEqual(counter.count, expectedCount)
  8. DIGITAL DAY - SEP 3, 2016 MARCÍLIO JÚNIOR [email protected] (B/T)DD

    • Test-Driven Development • Behaviour-Driven Development describe("Counter") { var counter: Counter! beforeEach { counter = Counter() } it("should increase count by 1 after calling tick") { let expectedCount = counter.count + 1 counter.tick() expect(counter.count).to(be(expectedCount)) } }
  9. DIGITAL DAY - SEP 3, 2016 MARCÍLIO JÚNIOR [email protected] TESTING

    frameworks • XCTest • default testing framework of Xcode • Quick
  10. DIGITAL DAY - SEP 3, 2016 MARCÍLIO JÚNIOR [email protected] TESTING

    frameworks • XCTest • Quick • BDD testing framework
  11. DIGITAL DAY - SEP 3, 2016 MARCÍLIO JÚNIOR [email protected] quick

    • https://github.com/Quick/Quick • Inspired by RSpec, Specta e Ginkgo • Swift & Objective-C support • It comes with a great matcher framework: Nimble
  12. DIGITAL DAY - SEP 3, 2016 MARCÍLIO JÚNIOR [email protected] quick

    • BDD DSL • describe • context • it • beforeEach • afterEach
  13. DIGITAL DAY - SEP 3, 2016 MARCÍLIO JÚNIOR [email protected] testable

    imports • @testable import • allows use your internal classes in unit test target • don’t need to set the unit test target to all your classes
  14. DIGITAL DAY - SEP 3, 2016 MARCÍLIO JÚNIOR [email protected] tips

    • Dependency injection • Testable architectures • Mocks & Stubs • Code Coverage
  15. DIGITAL DAY - SEP 3, 2016 MARCÍLIO JÚNIOR [email protected] thanks!

    @marciliojrs /in/marciliojunior [email protected] @marcilio iOSDevBR @marciliojrs