13
Stop Writing Unit Tests Ghadi Shayban healthfinch

Stop Writing Unit - functional.sc · Property-based Random testing Generative testing. Names of Tools Haskell (QuickCheck) 2000 Erlang (eqc) 2006 Python (Hypothesis) Clojure (test.check)

  • Upload
    others

  • View
    13

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Stop Writing Unit - functional.sc · Property-based Random testing Generative testing. Names of Tools Haskell (QuickCheck) 2000 Erlang (eqc) 2006 Python (Hypothesis) Clojure (test.check)

Stop Writing Unit Tests

Ghadi Shayban

healthfinch

Page 2: Stop Writing Unit - functional.sc · Property-based Random testing Generative testing. Names of Tools Haskell (QuickCheck) 2000 Erlang (eqc) 2006 Python (Hypothesis) Clojure (test.check)

Generate Them!

Page 3: Stop Writing Unit - functional.sc · Property-based Random testing Generative testing. Names of Tools Haskell (QuickCheck) 2000 Erlang (eqc) 2006 Python (Hypothesis) Clojure (test.check)

Testing Crutches

Foo

Bar

42

new Exception("BOOM")

Page 4: Stop Writing Unit - functional.sc · Property-based Random testing Generative testing. Names of Tools Haskell (QuickCheck) 2000 Erlang (eqc) 2006 Python (Hypothesis) Clojure (test.check)

Testing Crutches

assert_to_my_stakeholder( dumb_call(42) == "cherry-picked answer")

assert(obvious_failure_failed)

assert(you_are_paid_way_too_much_for_this)

Page 5: Stop Writing Unit - functional.sc · Property-based Random testing Generative testing. Names of Tools Haskell (QuickCheck) 2000 Erlang (eqc) 2006 Python (Hypothesis) Clojure (test.check)

State Space

Page 6: Stop Writing Unit - functional.sc · Property-based Random testing Generative testing. Names of Tools Haskell (QuickCheck) 2000 Erlang (eqc) 2006 Python (Hypothesis) Clojure (test.check)

What you're actually testing

State Space

Page 7: Stop Writing Unit - functional.sc · Property-based Random testing Generative testing. Names of Tools Haskell (QuickCheck) 2000 Erlang (eqc) 2006 Python (Hypothesis) Clojure (test.check)

Synonyms for This Topic

❖ Property-based

❖ Random testing

❖ Generative testing

Page 8: Stop Writing Unit - functional.sc · Property-based Random testing Generative testing. Names of Tools Haskell (QuickCheck) 2000 Erlang (eqc) 2006 Python (Hypothesis) Clojure (test.check)

Names of Tools

❖ Haskell (QuickCheck) 2000

❖ Erlang (eqc) 2006

❖ Python (Hypothesis)

❖ Clojure (test.check)

❖ Scala (ScalaCheck)

Page 9: Stop Writing Unit - functional.sc · Property-based Random testing Generative testing. Names of Tools Haskell (QuickCheck) 2000 Erlang (eqc) 2006 Python (Hypothesis) Clojure (test.check)

The Hope

State Space

Page 10: Stop Writing Unit - functional.sc · Property-based Random testing Generative testing. Names of Tools Haskell (QuickCheck) 2000 Erlang (eqc) 2006 Python (Hypothesis) Clojure (test.check)

Approach

1. Think Carefully™ about properties or invariants2. Code the properties3. Synthesize input 4. Run the properties over the input

Page 11: Stop Writing Unit - functional.sc · Property-based Random testing Generative testing. Names of Tools Haskell (QuickCheck) 2000 Erlang (eqc) 2006 Python (Hypothesis) Clojure (test.check)

https://stackoverflow.com/questions/38891409/static-analysis-and-symbolic-execution-in-implementation

Page 12: Stop Writing Unit - functional.sc · Property-based Random testing Generative testing. Names of Tools Haskell (QuickCheck) 2000 Erlang (eqc) 2006 Python (Hypothesis) Clojure (test.check)

(defn f [] (-> #{} (transient) (conj! -24) (persistent!) (conj 0) (conj 0) (conj 0) (conj 0) (conj 0) (conj 0) (transient) (conj! 23) (conj! 0) (conj! 0) (conj! 0) (conj! 0) (conj! 0) (conj! 0) (conj! 0) (conj! 0) (disj! 23) (persistent!) (conj 23)))

https://groups.google.com/forum/#!msg/clojure-dev/HvppNjEH5Qc/1wZ-6qE7nWgJ

Page 13: Stop Writing Unit - functional.sc · Property-based Random testing Generative testing. Names of Tools Haskell (QuickCheck) 2000 Erlang (eqc) 2006 Python (Hypothesis) Clojure (test.check)

Interactive Code