Property Based Testing Flashcards
What is property based testing?
Defining tests over invariant properties or specs. Sample tests from the input space
What is the concept behind property based testing?
Use formal reasoning and program analysis to make each unit test cover more behavior
A test scenario can be either _______ or ______
concrete (x=5), abstract (all x: x>0)
For abstract test cases, we can generate ________ and consult the _______. This is the motivation of property based testing
test-cases, oracle
What does property based testing process focus on?
Generating many tests for functional properties, Focussed on goals
Describe traditional and property testing
Traditional testing: Example based (concrete scenarios)
Property testing: Based on generic properties (for all x, y, z: f(x, y, z) -> g(x, y, z))
In random sampling, what is a generator?
A way to sample complex types for your properties. Some domains may require effort to represent
Property based testing can help developers ________ their code because the process is so spec focussed
understand
What are some common properties that we can test? Give an example for each
Symmetry (encode(decode(x)) == x) Alternatives (different sorts) Induction (car(cons(head,tail)) == head) Idempotence (sort(sort(x)) == sort(x)) Invariants (sort(x).size() == x.size())
What are good properties to check for a sorting function sort(x)?
Size does not change after sort is_ordered(x) All elements present in both lists, along with frequency freq(x) == freq(sort(x)) How can we resolve ties?
What are some benefits for property testing?
Tests have clear mathematical presentation
Testing process moves from examples to entire input space
Can decrease maintenance costs with same coverage
Failing tests have test case reduction applied