使用clojure.test创建一个“慢”测试套件 [英] Make a 'slow' test suite with clojure.test
问题描述
我想让此测试与每个 lein测试运行
:
(ns acker.core-test
(:require [clojure.test:refer:all]
[acker.core:refer:all]))
(deckest ackermann-test
(测试ack-1,ack-2,ack-3
(是[mne]
(=(ack-1 mn) ack-2 mn)(ack-3 mn)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
(测试ackermann(慢)
(是[mne](=(ack-3mn)e)
3 3 61
3 4 125
4 0 13
4 1 65533)))
Github上提供了完整的代码:https://github.com/bluemont/ackermann
根据Phil Hagelberg的让Leiningen为您工作, test-selectors
功能已添加到版本1.4中的 Leiningen 。
两个简单的步骤。首先,将它添加到 project.clj
:
:test-selectors {:default(complement:slow)
:slow:slow
:all(consistent true)}
其次,用元数据标记测试:
(deftest ^:slow ackermann-slow-test
(testackermann(slow)
(are [mne](=(ack-3 mn)e)
3 3 61
3 4 125
4 0 13
4 1 65533)))
$ b b
现在,您有三个选项可用于运行测试:
$ b⚡lein test:slow
⚡lein test:all
容易找到 lein test -h
:
运行项目的测试。 / p>
使用元数据标记deftest或ns表单允许您选择选择器
来指定要运行的测试套件的子集:(deftest ^:integration network-heavy-test
(is(= [1 2 3](:numbers(network-operation)))))
在project.clj中写入选择器:
:test-selectors {:default(complement:integration)
:integration:integration
:all(consistent true)}
如果它们是
关键字,则此任务的参数将被视为测试选择器,否则参数必须是测试命名空间或要运行的文件。
没有参数:使用default测试选择器(如果存在),
,否则运行所有测试。测试选择器参数必须在
命名空间列表之后。
默认值:只有test-selector可用于运行select测试。对于
示例,lein测试:只有leiningen.test.test / test-default-selector
只运行指定的测试。默认:所有测试选择器都是
,可用于运行所有测试。
参数:([& tests])
I want this test to run with every 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)))
I want to make ackermann-slow-test
only run when I ask for it:
(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)))
The full code is available on Github: https://github.com/bluemont/ackermann
According to Making Leiningen work for You by Phil Hagelberg, the test-selectors
feature was added to Leiningen in version 1.4.
Two easy steps. First, add this to project.clj
:
:test-selectors {:default (complement :slow)
:slow :slow
:all (constantly true)}
Second, mark up your test with metadata:
(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)))
Now you have three options for running your tests:
⚡ lein test
⚡ lein test :slow
⚡ lein test :all
Also, this information is easy to find with lein test -h
:
Run the project's tests.
Marking deftest or ns forms with metadata allows you to pick selectors to specify a subset of your test suite to run:
(deftest ^:integration network-heavy-test (is (= [1 2 3] (:numbers (network-operation)))))
Write the selectors in project.clj:
:test-selectors {:default (complement :integration) :integration :integration :all (constantly true)}
Arguments to this task will be considered test selectors if they are keywords, otherwise arguments must be test namespaces or files to run. With no arguments the :default test selector is used if present, otherwise all tests are run. Test selector arguments must come after the list of namespaces.
A default :only test-selector is available to run select tests. For example,
lein test :only leiningen.test.test/test-default-selector
only runs the specified test. A default :all test-selector is available to run all tests.Arguments: ([& tests])
这篇关于使用clojure.test创建一个“慢”测试套件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!