testando cum Midje
konrad scorciapino
@konr
diccionario
Middle English migge,
from Old English mycg;
akin to Old High German mucka
Latin musca
not really
syntaxe
clojure.test
(deftest arithmetic-works
(testing "with positive integers"
(is (= (+ 2 2) 4))
(is (= (+ 3 4) 7)))
midje
(facts "on arithmetic"
(fact "you can sum positive integers"
(+ 2 2) => 4
(+ 1000 1000 1000 1000)
=> 4000))
mocks
Funcção
(defn points [player]
(case (compute-status player)
:won 100
:draw 10
:lost 0))
Teste
(fact "a winner player gets 100 points"
(points "plínio") => 100
(provided
(compute-status "plínio") => :won))
alem de valores
funcções
(fact (+ 3 4) => prime?)
truthy et falsey
(facts
(empty? []) => truthy
(empty? [3]) => falsey)
throws
(fact "the universe won't divide"
(/ 1 0) => (throws Exception))
roughly, anything, &c
differentes typos de structura
sequenciaes
(fact
(range 10) => (contains 5) ;; [0, 1, 2, 3, ..., 9]
(range 3) => (just [even? odd? even?]))
mapas
(fact
{:age 27 :laughter "huahue"} => (contains {:age #(>= % 18)})
{:age 27 :laughter "huahue"} => (just {:age #(>= % 18)
:laughter #"(hu[a|e])+"}))
conjunctos
(fact
#{:foo :bar} => (contains :foo)
#{:foo :bar} => (two-of keyword?))
differentes typos de flechinha
(fact
(room-temperature) => (roughly 25 3)
(provided
(object-temperature) =streams=> [85 86 87]))
(fact
(gen-positive-number) =not=> #(< % 0))
&c
metaconstantes
(defn burger-combo [burger]
{:burger burger :free-drink (cheapest-drink)})
(fact "you get a free drink with the combo"
(burger-combo "delicious burger")
=contains=> {:free-drink "delicious drink"}
(provided (cheapest-drink) => "delicious drink"))
(fact "you get a free drink with the combo"
(burger-combo ..some-burger..)
=contains=> {:free-drink ..some-drink..}
(provided (cheapest-drink) => ..some-drink..))
factos tabulares
(fact "the charge with the highest value is charged in the end"
(divide-charges 9) => [4 5])
(tabular (fact "..."
(divide-charges ?total) => [?1st ?2nd])
?total ?1st ?2nd
100 50 50
99 49 50)
workflow
1. Programming by wishful thinking(defn format-page [...] (format-paragraph ...) ...)
2. REPLuser> (format-paragraph ..foo...) ..bar.. user>
(format-paragraph ..foo..) => ..bar..
WORKFLOW
> lein midje :autotest
...
> lein midje :autotest
...
workflow
> lein midje :autotest
...
====================================
Loading (foo.bar)
FAIL at (bar.clj:42)
Expected: 5
Actual: 4
FAILURE: 1 check failed. (But 1337 succeeded.)
:)
Midje
By Konrad Scorciapino
Midje
- 830