????????????·???
?????ThoughtWorks ???????[ 2016/11/22 14:17:11 ] ??????????????? ???????
????????????д????????
????“????????”??????????????????????????????????????????????????????????????????д?????????????????? ???????磺TDD??????????????? ???????????“???”???????????????????????????????????£????????????????е????????????
???????????????????????????????????????????????
??????????????????By Example??
??????????????????·??Given??When??Then????????
????· Given????????????????
????· When?????????
????· Then????????
??????д???????????????Given????????????????????????????????????????????????????????????????????????????TDD?????????????á??????????????????????????????????????????????С?????????
???????????????????л?????
????· ????????????????????????????壬????????????????????????? ????????????????????д??????kata?????????????е?????????????“return 3 when add 1 and 2”??????????????????????????????????????——?????????????????????add??????????????????????????????????????????????????????????????????????????????????????????
????· ????????????????????????????????????????????дhappy path????? ????????????£????????????????????·?????в??????????????????
?????????????????????????????????????????????——??????????Generative Testing?????Property-Based Testing?????????????????????????????????????????????????????????????????
?????????????
????????????????????????·????????????????д????????????????????????????????????????ж???????????????????????Given??When??Then????????ó????????????β????????????????“?????????”?????——????????????????????????????????????????????????????????????????????????????????
????Given???
????Clojure 1.9??Alpha?????????Clojure.spec?????????????????
????;; ????????????????????????????????
????(s/def ::add-operators (s/cat :a int? :b int?))
????;; ????????????
????(gen/generate (s/gen ::add-operators))
????;; ?????????
????-> (1 -122)
????????????????????????????????????????????????specification??????????a??b?????????????????????????????????????????????????????У???????漰????????????????????????????????????????????????????????????????——????????????return 3 when add 1 and 2????????????return the sum of two integers???????????塣
????Then???
????????????????????????????????????Then??????????????????????????????????????????????????????????????????????
??????????????????????
????(defn add [a b]
????(+ a b))
??????????????????????????? ???????????a??b??a??b??????????????a??b???? ????test.check????????Clojure???????????
????(def test-add
????(prop/for-all [a (gen/int)
????b (gen/int)]
????(= (add a b) (+ a b))))
???????????????add?????????(+ a b)д??????????????????????????????塣??????????????????ü??????????????????? ???????????????a??b?????????????a?????b??
????(def test-add
????(prop/for-all [a (gen/int)
????b (gen/int)]
????(= (- (add a b) a) b))))
???????????????????????????????????任??????????quick-check?????????????????в????
????;; ???????100?????????add????
????(tc/quick-check 100 test-add)
????;; ??????
????-> {:result true?? :num-tests 100?? :seed 1477285296502}
?????????????????????????100?????????????????????????????????????????????????????add?????????????????????????????????????????????????????????????????????????
?????????????????????????????????????????????????????????y??????????????Ч????????磺????????????ж??????????pairwise???????????????ù?????У??????????????????????????????????????????????????????????????identity-nat??????????????????????????????????????????е??????Ч???????????????1???????α????????????Χ???????????????????Ч?????????-1?? ??Clojure???????????????
????(deftest test-with-identity-nat
????(testing "identity of natural integers"
????(is (= 1 (identity-nat 1))))
????(testing "throw exception for non-natural integers"
????(is (thrown? RuntimeException (identity-nat -1)))))
???????????????????????identity-nat??????????????????0????????????????????????????????????????????????????????п??????????????á?????????????????????????μ??????????????塣???????????????????????????д????????????????????????????????β???????????????辯?棬??????????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11