2014-03-12 148 views
1

我是初學者用Clojure 我在(ns clojuregeek.test.contact)如何編寫測試用例Clojure中

寫道

(expect true (valid? "henry" "[email protected]" "9999999999" "tesxt message")) 

當我通過雷音測試Clojure中運行測試用例,我發現: -

lein test clojuregeek.test.contact 

Ran 0 tests containing 0 assertions. 
0 failures, 0 errors. 

failure in (contact.clj:32) : clojuregeek.test.contact 
(expect 
true 
(valid? "henry" "[email protected]" "9999999999" "tesxt message")) 

    act-msg: exception in actual: (valid? "henry" "[email protected]" "9999999999" "tesxt message") 
    threw: class java.lang.ClassCastException - clojure.lang.Var$Unbound cannot be cast to java.util.concurrent.Future 
      noir.validation$get_errors$doInvoke (validation.clj:94) 
      noir.validation$errors_QMARK_$doInvoke (validation.clj:140) 
      on (contact.clj:34) 
      on (contact.clj:32) 

Ran 1 tests containing 1 assertions in 178 msecs 
0 failures, 1 errors. 
+0

也許這有助於:http://yogthos.net/blog/46 – sloth

+1

很多lib-noir都沒有工作,除非你把代碼包裝在with-noir宏中。您的錯誤消息告訴我這是一個黑色問題,而不是測試問題。 – amalloy

回答

2

在Clojure開發Petri網模擬器時,測試環境Midje是最好的選擇編寫有用和簡單的測試用例。也許你只是看看這個...

測試用例非常簡單。您只需創建你的事實在test/core_tests.clj,如:

(ns your-namespace.core-tests 
    (:use midje.sweet) 
    :require [your-namespace.core :as core]) 

(fact "Testing valid?" 
    (core/valid? "henry" "[email protected]" "9999999999" "tesxt message") => true) 

;; some more facts... 

對於準備您需要修改project.clj

(defproject your-project "0.1.0-SNAPSHOT" 
    :description "" 
    :url "http://example.com/FIXME";TODO 
    :license {:name "Eclipse Public License" 
      :url "http://www.eclipse.org/legal/epl-v10.html"} 
    :dependencies [[org.clojure/clojure "1.5.1"] 
       [midje "1.6.2"]] 
    :main ^:skip-aot your-project.core 
    :target-path "target/%s" 
    :profiles {:uberjar {:aot :all} 
      :dev {:dependencies [[midje "1.6.2"]] 
        :plugins [[lein-midje "3.1.3"]]}}) 

在這之後,你可以在你的項目文件夾中啓動一個新的終端窗口並輸入第一lein deps和在此之後:

lein midje :autotest 

和Midje將在您每次將項目保存到項目中時通過測試DER。

在我看來,寫出簡單實用的測試用例是最好的解決方案之一。

+0

謝謝amalloy – user3409548

相關問題