Fork me on GitHub
#testing
<
2021-05-26
>
Niklas14:05:33

I'm playing with the usefulness of nested tests, but the cognitect test-runner runs all tests, which means it runs the same tests twice.

(ns a-test
  (:require [clojure.test :refer [deftest is]]))

(deftest ^:subtest a-test
  (is (= 1 0)))

(deftest ^:subtest b-test
  (is (= 1 1)))

(deftest c-test
  (a-test)
  (b-test))
$ clj -X:test

Running tests in #{"test"}

Testing a-test

FAIL in (a-test) (a_test.clj:6)
expected: (= 1 0)
  actual: (not (= 1 0))

FAIL in (c-test a-test) (a_test.clj:6)
expected: (= 1 0)
  actual: (not (= 1 0))

Ran 5 tests containing 4 assertions.
2 failures, 0 errors.
$ clj -X:test :excludes '[:subtest]'

Running tests in #{"test"}

Testing a-test

Ran 1 tests containing 0 assertions.
0 failures, 0 errors.

Niklas14:05:19

In the last code box I try to only run the c-test however then it skips the a-test ...

Niklas15:05:13

testing can be used to get nested contexts, but testings cannot be run as individual tests, so that isn't very developer friendly..

Noah Bogart15:05:34

what about writing them as basic functions? clojure.test is built on dynamic variables, so using is should still work when a-fn is called from inside c-test

Noah Bogart15:05:55

is there a specific reason you need them to be deftest s?