property based testing
play

Property-Based Testing Matt Bachmann @mattbachmann Testing is - PowerPoint PPT Presentation

Property-Based Testing Matt Bachmann @mattbachmann Testing is Important Testing is Important Testing is Important Testing is Hard Testing is Hard Testing is Hard Capture the Important Cases Minimize The Coding Overhead Sorting a list of


  1. Compare Against Brute Force

  2. @given(st.lists(st.integers())) def test_against_brute_force(input): assert ( easy_but_inefficent(input) == optimized(input) )

  3. The System

  4. The System

  5. The System

  6. The System

  7. Pattern 4: Invariants

  8. Stateful Tests ● Define a state ● What operations can happen in what conditions? ● How do operations affect the state? ● What must be true for each step?

  9. https://commons.wikimedia.org/wiki/File:Max-Heap.svg http://hypothesis.works/articles/rule-based-stateful-testing/

  10. Invariant ● No matter what series of operations is performed the head of the tree must be the max element

  11. __init__ push pop merge http://hypothesis.works/articles/rule-based-stateful-testing/

  12. FIND. ME. BUGS.

  13. Heaps Integers http://hypothesis.works/articles/rule-based-stateful-testing/

  14. Heaps __init__ Integers http://hypothesis.works/articles/rule-based-stateful-testing/

  15. Heaps push Integers http://hypothesis.works/articles/rule-based-stateful-testing/

  16. Heaps merge Integers http://hypothesis.works/articles/rule-based-stateful-testing/

  17. Heaps pop Integers assert result actually max http://hypothesis.works/articles/rule-based-stateful-testing/

  18. class HeapMachine(RuleBasedStateMachine): Heaps = Bundle('heaps') @rule(target=Heaps) def new_heap(self): return Heap() @rule(heap=Heaps, value=integers()) def heap_push(self, heap, value): push(heap, value) http://hypothesis.works/articles/rule-based-stateful-testing/

  19. class HeapMachine(RuleBasedStateMachine): Heaps = Bundle('heaps') @rule(target=Heaps) def new_heap(self): return Heap() @rule(heap=Heaps, value=integers()) def heap_push(self, heap, value): push(heap, value) http://hypothesis.works/articles/rule-based-stateful-testing/

Recommend


More recommend