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

"Snapshot testing with FBSnapshotTestCase" by A...

"Snapshot testing with FBSnapshotTestCase" by Ahmed Sulaiman

This talk was made for CocoaHeads Kyiv #10 which took place 10 Dec 2016, and it gives a brief introduction to FBSnapshotTestCase, describes how to use it properly and motivates you to use it.

CocoaHeads Ukraine

December 22, 2016
Tweet

More Decks by CocoaHeads Ukraine

Other Decks in Programming

Transcript

  1. iPhone 6 – iOS 10.1 (23E233) FLAWLESS APP Real-time comparison

    of expected and implemented design. Built into iOS simulator.
  2. @ahmed_sulajman WHY Why you should use snapshot tests How to

    write snapshot tests Ques8ons and answers HOW Q&A
  3. @ahmed_sulajman WHY How to write snapshot tests HOW Q&A Why

    you should use snapshot tests Ques8ons and answers
  4. @ahmed_sulajman WHY How to write snapshot tests HOW Q&A Why

    you should use snapshot tests Ques8ons and answers
  5. @ahmed_sulajman HOW: CREATE SNAPSHOT TEST WRITE THE TEST Init View

    with needed condi5ons and verify it func testLoginButton() { let loginButton = LoginButton() loginButton.setTitle("Sign in", for: .normal) FBSnapshotVerifyView(view: loginButton) }
  6. @ahmed_sulajman HOW: CREATE SNAPSHOT TEST RECORD REFERENCES override func setUp()

    { super.setUp() recordMode = true } Record reference images of testable views
  7. @ahmed_sulajman HOW: CREATE SNAPSHOT TEST COMPARE RESULT Compare the difference

    between reference image and real view Reference Real Diff
  8. @ahmed_sulajman WHY How to write snapshot tests HOW Q&A Why

    you should use snapshot tests Ques8ons and answers
  9. @ahmed_sulajman Q&A: HOW TO DEAL WITH ANIMATION DRAW LAST STATE

    This method is smart enough to render the view’s final state UIView func drawHierarchy(in rect: CGRect, afterScreenUpdates afterUpdates: Bool) -> Bool
  10. @ahmed_sulajman Q&A: HOW TO DEAL WITH ANIMATIONS TURN OFF ANIMATION

    Rewrite components to have an ability to turn off anima:on at any :me UISwitch func setOn(_ on: Bool, animated: Bool)
  11. @ahmed_sulajman Q&A: HOW LONG IMAGE COMPARISON MAY TAKE AVERAGE =

    0.008s On a Macbook Air 2012 int memcmp(const void *ptr1, const void *ptr2, size_t num);
  12. @ahmed_sulajman SUMMARY – DISADVANTAGES ASYNC STANDARD UI Hard to test

    async code Apple could change style of standard UI
  13. @ahmed_sulajman SUMMARY – DISADVANTAGES ASYNC STANDARD UI DISK SPACE Hard

    to test async code Apple could change style of standard UI Every reference image is a .png file
  14. @ahmed_sulajman SUMMARY – ADVANTAGES EDGE CASES CONCURRENT Detect possible UI

    elements edge cases Snapshot tests runs at the same :me as other tests
  15. @ahmed_sulajman SUMMARY – ADVANTAGES EDGE CASES CONCURRENT SEPARATION Detect possible

    UI elements edge cases Snapshot tests runs at the same :me as other tests Separate logical and visual changes 10010 11001 11100 01100 10001
  16. @ahmed_sulajman SUMMARY – ADVANTAGES EDGE CASES DESIGN REVIEW CONCURRENT SEPARATION

    Detect possible UI elements edge cases Involve designer in code review process Snapshot tests runs at the same <me as other tests Separate logical and visual changes 10010 11001 11100 01100 10001
  17. @ahmed_sulajman SUMMARY – ADVANTAGES EDGE CASES DESIGN REVIEW SPEED CONCURRENT

    SEPARATION Detect possible UI elements edge cases Involve designer in code review process Snapshot tests are fast enough Snapshot tests runs at the same =me as other tests Separate logical and visual changes 10010 11001 11100 01100 10001