0

I am trying to understand the use case FBSnapshotTestcase solves. We already have native apple lib named xcuiscreenshot. Whenever any UITest fails, it automatically takes screenshot of the view for reference.

FBSnapshotTestcase compares with the previously stored reference image to declare a failure of screen in terms of it desired UI.

But in practical what is the exact advantage of using FBSnapTestCase over XCUIScreenshot?

user804417
  • 155
  • 2
  • 13

1 Answers1

2

I use FBSnapshotTestCase because I want to snapshot from a unit test target, not a UI test target.

The chief advantage is saving time. Instead of launching the app, attaching to it, and navigating to each screen, you can just instantiate view controllers directly.

Jon Reid
  • 20,545
  • 2
  • 64
  • 95
  • Thank You Sir for answer! I am overwhelmed seeing Your answer, I follow You for long time, I follow your qualitycoding. Now coming to the question, taking snapshot from unit test target would save time, since running UItest is expensive. So saving time of running UItest target is advantage of using FBSnapshotTestcase? Currently in our project we are dong unit testing and UItesting. Now if I want to justify the use of introducing a 3rd party framework, saving time of running UItest can be the only justification point or there are more? – user804417 Apr 04 '21 at 08:20
  • 1
    Time is the big win. You should evaluate whether to use FBSnapshotTestCase or something else like https://github.com/pointfreeco/swift-snapshot-testing – Jon Reid Apr 04 '21 at 14:58
  • Can we say snapshot testing can replace the need of UITest/ Automation testing to an extend if not completely? And instead from Unittest target we extract the benefit of UITesting using snapshot? – user804417 Apr 09 '21 at 08:11
  • 1
    I have very little need of UITests. – Jon Reid Apr 10 '21 at 00:52
  • If you can point out one use case where unit/ snapshot can not cover & we must have an UITest that will be really helpful. We recently added dark mode support for our app. Currently I am trying to test all my views are behaving properly in dark mode. Can you think of any use case where snapshot testing can not cover all the case? – user804417 Apr 12 '21 at 14:50
  • 1
    Unit test snapshots where the keyboard is showing take some playing around to get them right. And the result has a blank area instead of an actual keyboard. So those snapshots are less realistic (don't show them to product owners without warning them) but still useful for developers. – Jon Reid Apr 12 '21 at 18:28
  • may be a session on your quality coding YouTube channel on snapshot and its nuances will be helpful! – user804417 Apr 14 '21 at 16:00
  • Any leads how can we use Snapshot testing to test darkmode implementation? Or any other testing strategy for dark mode? – user804417 Apr 19 '21 at 06:26
  • 1
    That's a really good question. I think it would be good to open a separate Question for it. – Jon Reid Apr 19 '21 at 15:44
  • Thank You Jon, opened a new question on the same : https://stackoverflow.com/questions/67167854/testing-dark-mode-using-snapshot-testing – user804417 Apr 20 '21 at 03:51