Mais conteúdo relacionado Semelhante a Clojrue 13 testing (20) Mais de Kiyotaka Kunihira (20) Clojrue 13 testing6. is Sample
• (require ‘clojure/test)
• (is (= 1 2) “one is not two”)
‣ FAIL in clojure.lang.PersistentList$EmptyList@1
(NO_SOURCE_FILE:17)
‣ one is not two ←アサーションメッセージ
‣ expected: (= 1 2)
‣ actual: (not (= 1 2))
‣ false
8. thrown? sample (1/2)
• (is (thrown? ArithmeticException (/ 1 0)))
‣ #<ArithmeticException
java.lang.ArithmeticException: Divide by
zero>
9. thrown? sample (2/2)
• (is (thrown-with-msg? ArithmeticException
#"zero" (/ 1 0)))
‣ #<ArithmeticException
java.lang.ArithmeticException: Divide by
zero>
• 第2引数に正規表現を指定すると、エ
ラーのメッセージにその表現が含まれ
るかどうかまでテスト可能
11. deftest sample
• (deftest test-foo2
(is (= 1 1) "one is not onw")
(is (= 1 2) "one is not two"))
‣ #'user/test-foo2
• ((:test (meta #'test-foo2)))
‣ FAIL in clojure.lang.PersistentList$EmptyList@1
(NO_SOURCE_FILE:27)
‣ one is not two
‣ expected: (= 1 2)
‣ actual: (not (= 1 2))
‣ false
13. with-testサンプル(1/2)
• (with-test
(defn hello [name]
(str "Hello, " name))
(is (= hello "Brian") "Hello, Brian")
(is (= (hello "Boo") "Hello, Foo" ) "hogehoge") )
‣ #'user/hello
• (run-tests)
‣ Testing user
‣ FAIL in (hello) (NO_SOURCE_FILE:32)
‣ Hello, Brian
‣ expected: (= hello "Brian")
‣ actual: (not (= #<user$eval56$hello__57 user
$eval56$hello__57@23de4dd8> "Brian"))
14. with-testサンプル(2/2)
• (with-test
(defn hello [name]
(str "Hello, " name))
(is (= hello "Brian") "Hello, Brian")
(is (= (hello "Boo") "Hello, Foo" ) "hogehoge") )
‣ #'user/hello
• (run-tests)
‣ Testing user
‣ FAIL in (hello) (NO_SOURCE_FILE:32)
‣ Hello, Brian
‣ expected: (= hello "Brian")
‣ actual: (not (= #<user$eval56$hello__57 user
$eval56$hello__57@23de4dd8> "Brian"))
Notas do Editor \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n