Clojure/leiningenでユニットテストを実行する
leiningenを使っているプロジェクトで、ユニットテストを実行する方法について整理します。
ユニットテストを実行する
$ lein test
特定のnamespaceのユニットテストだけ実行する
$ lein test sample-app.core-test
テストをメタキーワードでグルーピングして、そのグループのテストだけを実行する
project.cljにtest-selectorsを追加する
.
.
:test-selectors {:api :api
:model :model
:core :core)}
.
テストコードにキーワードを指定する
(ns ^:core sample-app.core-test
(require [clojure.test :refer :all]
[sample-app.core :refer :all]))
(deftest ^:api a-test
(testing "TEST A"
(is (= 1 (+ 1 1)))))
(deftest ^:model b-test
(testing "TEST B"
(is (= 1 (- 2 1)))))
キーワードを指定して lein testを実行する
# :modelメタキーワードが設定されたb-testだけ実行 $ lein test :model # :apiメタキーワードが設定されたa-testだけ実行 $ lein test :api # :coreメタキーワードが設定されたsample-app.core-testに含まれるa-testとb-testが実行される $ lein test :core
特定の関数だけテストする
$ lein test :only sample-app.core-test/a-test