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

Snapshot testing in iOS

Snapshot testing in iOS

Snapshot testing is a way of ensuring that your views look correctly in every possible configuration, size and language (among others). It tries to bridge the gap between unit tests and manual or UI tests. You can learn from the slides about snapshot testing itself, its pros and cons, and to see some examples of real-life scenarios.

Avatar for Bartłomiej Hyży

Bartłomiej Hyży

April 11, 2019
Tweet

Other Decks in Programming

Transcript

  1. Mobile test types Unit tests Integration tests UI tests Manual

    tests Complexity Quantity Snapshot tests }
  2. Visuals influenced by… ‣ Screen resolution ‣ Language ‣ Device

    orientation ‣ Interface idiom (phone, pad, TV, CarPlay) ‣ Application state
  3. Combinatorial explosion ๏ 1 UI element, e.g. button ๏ 3

    states (normal, highlighted, disabled) ๏ 2 configurations (normal, with subtitle) ๏ 10 languages ๏ 2 styles (light, dark) 1 × 3 × 2 × 10 × 2 = 120 combinations
  4. Pranoto Stockholm Arlanda Airport Samarinda Aji Pangeran Tumenggung Pranoto Int'l

    Airport Samarinda Aji Pangeran Tumenggung International Airport
  5. Pros + Quickly validate numerous view forms + Detect subtle

    issues in reused components + Much faster than UI tests — no navigation, animations
  6. Pros + Promote well-designed APIs and good programming practices •

    Lightweight views/controllers • Abstraction • Dependency injection
  7. Cons - Occasional flakiness - Animations and interactions not tested

    - Might need good image diff tool, e.g. Kaleidoscope
  8. Cons - Some features trickier to test (e.g. size classes,

    UIAppearance) - Complex screens and scenarios might require hacky solutions
  9. Cons - Repository can grow in size considerably ‣ Snapshots

    of entire screens ‣ Large Retina displays ‣ 2x/3x images ‣ Large, scrollable content
  10. Cons ‣ Choose your tests wisely ‣ Purge snapshots from

    history ‣ Use Git LFS - Repository can grow in size considerably
  11. Git LFS git add Snapshots/some_huge_snapshot.png
 git commit Snapshots/some_huge_snapshot.png
 2 MB

    +2 MB +2 MB Screen under test modified git add Snapshots/some_huge_snapshot.png
 git commit