我希望此测试与每个lein test
:
(ns acker.core-test
(:require [clojure.test :refer :all]
[acker.core :refer :all]))
(deftest ackermann-test
(testing "ack-1, ack-2, ack-3"
(are [m n e]
(= (ack-1 m n) (ack-2 m n) (ack-3 m n) e)
0 0 1
0 1 2
0 2 3
1 0 2
1 1 3
1 2 4
2 0 3
2 1 5
2 2 7
3 0 5
3 1 13
3 2 29)))
我想让ackermann-slow-test
仅在我要求时运行:
(deftest ackermann-slow-test
(testing "ackermann (slow)"
(are [m n e] (= (ack-3 m n) e)
3 3 61
3 4 125
4 0 13
4 1 65533)))
完整代码可在Github上找到:https://github.com/bluemont/ackermann
答案 0 :(得分:28)
根据Phil Hagelberg的Making Leiningen work for You,test-selectors
功能已在版本1.4中添加到Leiningen。
两个简单的步骤。首先,将其添加到project.clj
:
:test-selectors {:default (complement :slow)
:slow :slow
:all (constantly true)}
其次,使用元数据标记您的测试:
(deftest ^:slow ackermann-slow-test
(testing "ackermann (slow)"
(are [m n e] (= (ack-3 m n) e)
3 3 61
3 4 125
4 0 13
4 1 65533)))
现在您有三种运行测试的选项:
⚡ lein test
⚡ lein test :slow
⚡ lein test :all
此外,使用lein test -h
:
运行项目的测试。
使用元数据标记deftest或ns表单可以选择选择器 指定要运行的测试套件的子集:
(deftest ^:integration network-heavy-test (is (= [1 2 3] (:numbers (network-operation)))))
在project.clj中编写选择器:
:test-selectors {:default (complement :integration) :integration :integration :all (constantly true)}
此任务的参数如果是,则将被视为测试选择器 关键字,否则参数必须是测试命名空间或要运行的文件。 没有参数:如果存在,则使用默认测试选择器, 否则所有测试都会运行。测试选择器参数必须在之后 命名空间列表。
默认值:只有测试选择器可用于运行选择测试。对于 例如,
lein test :only leiningen.test.test/test-default-selector
只运行指定的测试。默认值:所有测试选择器都是 可以运行所有测试。参数:([& tests])