Run tests from Clojure Repl and Leiningen

后端 未结 3 1949
自闭症患者
自闭症患者 2021-01-31 08:14

As a newbie to clojure, I have used leiningen to create a sample project with

lein new app first-project

which gave me this directory



        
3条回答
  •  孤独总比滥情好
    2021-01-31 09:00

    To recap:

    Way of require

    Full qualification of functions is only needed if you issued an in-ns earlier. Then do:

    (clojure.core/require '[clojure.core :refer [require]]
                          '[clojure.test :refer [run-tests]]
                          '[clojure.repl :refer [dir]])
    

    ; Load whatever is in namespace "foo.bar-test" and reload everything
    ; if `:reload-all` has been additionally given
    
    (require 'foo.bar-test :reload-all) 
    ;=> nil
    
    ; List your tests for good measure (Note: don't quote the namespace symbol!)
    
    (dir foo.bar-test)
    ;=> t-math
    ;=> t-arith
    ;=> t-exponential
    ;=> nil 
    
    ; Check meta-information on a test to verify selector for example 
    
    (meta #'foo.bar-test/t-math)
    ;=> {:basic-math true, :test #object[foo.bar_tes...
    
    ; `run-tests` will probably run nothing because the current namespace
    ; doesn't contain any tests, unless you have changed it with "in-ns"
    
    (run-tests) 
    ;=> Ran 0 tests containing 0 assertions.
    
    ; run tests by giving namespace explicitly instead
    
    (run-tests 'foo.bar-test) 
    ;=> Ran 3 tests containing 29 assertions.
    

提交回复
热议问题