Time Travelling and Fixing Bugs with Property-Based Testing (2019)
13 points by abhin4v
13 points by abhin4v
Date and time logic is one of the best domains for property based testing of pure logic. I have a tiny personal finance app that uses iCalendar rrule expansion to figure out when recurring bills are due, and PBT caught so many bugs related to daylight savings and time zones.
I personally think PBT should be the default, but for those who aren’t as bullish, dates and times is one area that definitely hits the sweet spot at least.
That, and it also works wonderfully for any pure datastructure. One time I was trying to implement the Fugue CRDT, and I thought it was working. Then I've implemented a PBT suite that randomly inserted/removed text from the CRDT, simulating multiple clients. It worked so great that I stopped working on that project, because the PBT suite kept finding bugs, lol.
Recently I've been using a PBT suite to test web components. Imagine the user doing multiple actions on a list view, such as "Move item Down", "Move item Up", "Copy item", "Paste item", "Delete item". The tests can perform the actions on the 'list-view' component, then check if the DOM has updated as expected. If you define the commands to be executed as keyboard inputs over the browser, instead of function calls to the web component, you are testing accessibility as well.