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

标签 testing clojure

我希望此测试与每个 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/

相关文章:

java - 两次第二次 ArgumentCaptor.capture() in Mockito.when()

testing - Gitlab+测试用例管理工具

drupal - 链接继续指向实时服务器 - Drupal Live 到本地主机

unit-testing - JUnit 使用嵌入式服务器测试 Cassandra

go - 在 Go 包函数中模拟函数

oracle - Clojure Lein 找不到 Oracle JDBC 驱动程序

swing - 将简单的 Ltk-app 翻译成 Clojure seesaw/swing

windows - Leiningen 终止批处理文件的执行

clojure - 在 Clojure 中重写一系列 if 语句

clojure - Compojure 没有得到请求正文