Better tests automagically (big sky dev con 2015)
Transcript of Better tests automagically (big sky dev con 2015)
Good arguments for that
● Finite time for writing tests● Maintaining test code is expensive● I’m just not that creative
How hard do you test edge cases?
● Test with Unicode most days?● Insert control characters into strings?● Throw negative values at your numbers?● Toss empty containers at utility functions?● Combine multiple edge cases in one test?
Typical Unit Testing Flow
1. You provide code of questionable quality2. You provide input values to your functions3. You hope not comically misrepresentative4. You use the values to do something useful5. You verify useful thing has expected result
Typical Unit Testing Flow
1. You provide code of questionable quality2. You provide input values to your functions3. You hope not comically misrepresentative4. You use the values to do something useful5. You verify useful thing has expected result
Enter Property Testing
1. You provide code of questionable quality2. You provide specification of kinds of inputs3. It provides values to kick your butt4. You use the values to do something useful5. You verify useful thing has expected result
When to Use Property Tests
● Not always● Natural round-tripping, symmetric functions
o Serialization/Deserializationo Protocols
● Two equivalent algorithms● Natural invariants● General utility functions
o May need to resort to heuristic
What’s not to Like?
● Relatively slow to execute● More to to get a basic level of coverage● Documentation tends to be thin
Can I Use Property Testing?
● Scala● Haskell● JavaScript● Ruby● Python● C# and .NET● Java● Closure
Others too!
From this old list