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

Dylan Maryk - How can my unit and UI tests not ...

Avatar for CocoaHeads Berlin CocoaHeads Berlin
December 04, 2020
61

Dylan Maryk - How can my unit and UI tests not suck?

In this talk we'll go through some tips for improving your unit and UI testing, based on the libraries, setup and processes we've been using.

Dylan is an iOS developer at door2door, working on the future of shared mobility.

Video: https://youtu.be/zQUBSUe_oOk

Avatar for CocoaHeads Berlin

CocoaHeads Berlin

December 04, 2020
Tweet

Transcript

  1. Why weren’t we writing many tests? • Apple’s test suite

    offers poor syntax • ✍ They’re difficult to write • They take a long time to write • All-round bad developer experience
  2. Our architecture: MVP+ Presenter Business logic Mock view Mock dependency

    E.g. Networking Mock dependency E.g. User manager Mock delegate
  3. What we want to achieve with mocks • Mocking dependencies

    of the target class ◦ We don’t want to test networking or data storage when we’re testing the target class • Mocking objects “affected by” the target class ◦ We want to test functions of other classes are called ◦ Delegates ◦ Views
  4. New libraries! • Quick + Nimble ◦ Quick: Syntax based

    on RSpec, readable tests ◦ Nimble: Readable, feature-rich assertions • Cuckoo ◦ Easy mocking of dependencies and protocols ◦ Verify that functions of mocks are called
  5. Top tips! • ➗ Separate and test only your business

    logic • Force unwrap: don’t worry about null safety • Let your tests influence your dependency structure
  6. Original problem • No automated method of testing that flows

    through the app work as expected end-to-end • ⚒ Relied solely on manual testing, in particular to test the core flow before a release
  7. Positives • Automation of going through a few of our

    core flows would save a large amount of developer time • During the development of specific features it would help to ensure that the UX always behaves as expected
  8. New library: Succulent • ⏺ Records and replays network requests

    • ⏯ Removes flakiness of performing real requests on every run
  9. Top tips! • Test only your core flows • Reset

    any cached data • Avoid network requests where possible • Consider not running tests on CI on every commit
  10. Links • Quick: github.com/Quick/Quick • Nimble: github.com/Quick/Nimble • Cuckoo: github.com/Brightify/Cuckoo

    • Succulent: github.com/cactuslab/Succulent • Articles: medium.com/@dylanmaryk • Twitter: twitter.com/DylanMaryk