ubitricity / snapshotter

MIT License
8 stars 2 forks source link

Request for clarification #3

Open ocovalschi opened 4 years ago

ocovalschi commented 4 years ago

Hello,

I have a question regarding "What is snapshot testing?".

The first time the test is executed and the snapshot is saved. I assume that the snapshot is considered a "correct" result and becomes "expected" value. The question is, why do we need a snapshot if we can check for the correctness similar to the first time? What would be different from first time vs. subsequent runs?

Thank you in advance.

pmajcher commented 4 years ago

Hello @ocovalschi,

It's exactly as you wrote, snapshot is considered a "correct" result and becomes "expected" value.. Without the snapshotter, you would need to handcraft expected value, for instance json response. You would need to store this for instance as a file and and use it in the test. That's exactly what snapshotter does automatically. When you run it for the first time, snapshotter stores the result as a "snapshot". So when you run the snapshot based test for the first time, it will always pass. All subsequent runs will use a file stored by the snapshotter as an expected value.

There are also other useful features comparing to using handcrafted files as an expected values. You can for instance configure snapshotter to ignore values of some JSON nodes to be able to test code generating some date time or random ids.

Please let me know if you have more questions.

Take care!