gpt4 book ai didi

testing - 使用 clojure.test 创建一个 'slow' 测试套件

转载 作者:行者123 更新时间:2023-11-28 19:40:59 25 4
gpt4 key购买 nike

我希望此测试与每个 lein 测试 一起运行:

(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

最佳答案

根据 Making Leiningen work for You Phil Hagelberg 将 test-selectors 功能添加到 Leiningen在 1.4 版中。

两个简单的步骤。首先,将其添加到 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 很容易找到此信息:

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])

关于testing - 使用 clojure.test 创建一个 'slow' 测试套件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23017733/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com