Beklenen bir özel durum getiren bir işlevi nasıl test edebilirim? İşte istisna atar fonksiyonudur:Beklenen bir özel durumla başa çıkmak için nasıl bir sınama yazabilirim?
(defn seq-of-maps?
"Tests for a sequence of maps, and throws a custom exception if not."
[s-o-m]
(if-not (seq? s-o-m)
(throw (IllegalArgumentException. "s-o-m is not a sequence"))
(if-not (map? (first s-o-m))
(throw (IllegalArgumentException. "s-o-m is not a sequence of maps."))
true)))
ben bir istisna atılır ve yakalanmış ve daha sonra karşılaştırılır edildiği aşağıdaki gibi bir testi tasarım istiyorum. Açıkçası
Testing util.test.core
FAIL in (test-seq-of-maps) (core.clj:27)
expected: (not (= excp1 "s-o-m is not a sequence"))
actual: (not (not true))
Ran 2 tests containing 6 assertions.
1 failures, 0 errors.
Testleri yazma hakkında bir şey eksik:
(deftest test-seq-of-maps
(let [map1 {:key1 "val1"}
empv []
s-o-m (list {:key1 "val1"}{:key2 "val2"})
excp1 (try
(seq-of-maps? map1)
(catch Exception e (.getMessage e)))]
(is (seq-of-maps? s-o-m))
(is (not (= excp1 "s-o-m is not a sequence")))))
Bu hataları alıyorum: Aşağıdaki çalışmaz. Bunu anlamakta zorlanıyorum. Projem lein le ile kuruldu ve testleri lein testi ile yapıyorum.
Teşekkürler.
olası bir kopyası [Bir birim sınamasında nasıl bir hata bekleyebilirim?] (Http://stackoverflow.com/questions/7852092/how-do-i-expect-failure-in-a-unit-test) –