Run tests from Clojure Repl and Leiningen

后端 未结 3 1980
自闭症患者
自闭症患者 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:02

    In your example above the repl is in the wrong namespace. It may work better if you switch the repl to the core_test namespace. and then run (run-tests).

    (in-ns 'first-project.core-test)
    (run-tests)
    

    Another fun way of developing tests is to just run them from the REPL until they work, because tests are normal functions with some extra metadata.

    (in-ns 'first-project.core-test)
    (my-test)
    

    Remember you have to load the file in addition to calling in-ns Let's say your test file is tests/first_project/core_test.clj, then you will need to call

    (load "tests/first_project/core_test")
    (in-ns 'first-project.core-test)
    (my-test)
    

    Keep in mind that _ in the file system becomes - in the namespace and / becomes ..

提交回复
热议问题