2014-03-12 251 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

相关问题