This page is not created by, affiliated with, or supported by Slack Technologies, Inc.


I'm sorry if I'm repeating an oft-asked and answered question, but I'm really struggling with how to write properties to test my functionality without re-implementing the code I'm testing. Does anyone have a solid resource with some nice examples that could lead me out of the wilderness here?


@jmglov I like to say that generative testing is easy - the only hard parts are the generators and the properties


I took a stab at this topic of finding good properties in Clojure Applied, ch 8


I haven’t seen that link from @nwjsmith before but seems like generally good advice


I’ve been working on a tool that can help with finding properties.


It will take a set of properties, and the arg and return generators (e.g. from spec’s fdef), and generate a mutation of the function under test


Then it will run the mutant through the properties. If the mutant passes, then the tool reports an error.


It presents the mutant, which is usually very simple, and that can guide you to your next property. You play “whack-a-mutant” until no mutants pass.


An example: let’s say we’re writing properties for sort, you might start with the property that the input and output lists have the same count


This tool will generate a really simple mutant that passes all the properties, like (fn [x] (if (= x [1]) [2] (sort x)))


We want to whack this mutant (which isn’t our sort function). So we write a property that the input and output lists have to have the same elements. Our tool finds a new mutant that passes our properties (fn [x] (if (= x [1 2]) [2 1] (sort x)))


Finally, we write a property that says the elements of the return list should be in ascending order, and the tool reports no new mutants. This means we’ve written a complete set of properties