Make Good Stubs with Stateful Property Testing

submited by
Style Pass
2024-07-26 23:00:02

In a previous post, I wrote about how using stateful property testing helped us find test cases that were hard to find by hand. This helped us complete a project in a timely fashion. But some other surprising benefits came from introducing stateful property testing.

To switch from a deprecated MongoDB driver to the official one, we created a regression test suite. We first added stateful property tests, ensuring we covered as much behavior of the deprecated driver as we could. We then could make the new driver behave the same way as the the old one by making it pass those same tests. This gave us the confidence that both drivers behaved the same, even in edge cases, and that we could switch.

Well, having now these stateful property tests acting as a regression test suite, what else can we use them for? Creating stubs.

Integration tests comprises a broad spectrum of test implementation. On one side, you have the tests using real components, like a full MongoDB or Elasticsearch cluster. Those suffer, from my experience, from flakiness, hard to reproduce differences on local dev and CI and are resource intensive and slow.

Leave a Comment