Property Based Testing Flashcards

1
Q

What is property based testing?

A

Defining tests over invariant properties or specs. Sample tests from the input space

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the concept behind property based testing?

A

Use formal reasoning and program analysis to make each unit test cover more behavior

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

A test scenario can be either _______ or ______

A

concrete (x=5), abstract (all x: x>0)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

For abstract test cases, we can generate ________ and consult the _______. This is the motivation of property based testing

A

test-cases, oracle

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does property based testing process focus on?

A

Generating many tests for functional properties, Focussed on goals

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Describe traditional and property testing

A

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))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

In random sampling, what is a generator?

A

A way to sample complex types for your properties. Some domains may require effort to represent

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Property based testing can help developers ________ their code because the process is so spec focussed

A

understand

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are some common properties that we can test? Give an example for each

A
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())
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are good properties to check for a sorting function sort(x)?

A
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?
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are some benefits for property testing?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly