What is a ‘Snapshot’?

According to Urban Dictionary, a snapshot is what people that aren’t up to date call screenshots.

Duh… totally clear. To a Django developer, a snapshot looks like,

snapshots['SnapshotTests::test_choices_list_zero 1'] = { 'count': 0, 'next': None, 'previous': None, 'results': [] }

Let’s read the above python code, snapshots is a dict with key ‘SnapshotTests::test_choices_list_zero 1’ . This key is assigned a JSON object value {…}. This JSON object is the response of the API endpoint GET /api/choices/ . This JSON object is a snapshot of the API response.

If we assume this JSON object is the expected response and we make code changes as one does, we can test the functionality of GET /api/choices/ by calling it at any point as comparing the response with the previously saved snapshot response. If the responses match, then the API works as before. If the responses don’t match, then look for what caused the change. If the change in the response is intentional, save the new response as the updated snapshot. The best part about snapshot testing is that the snapshots are auto-generated. Yes, the above python code was automatically generated and not manually written. …


Gulfaraz Rahman

Optimizing for Utility. Delivering Intelligence. Founder of Just A.I.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store