testing

Testing tools, testing philosophy & methodology...
Niklas 2021-05-26T14:50:33.003600Z

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.

Niklas 2021-05-26T14:52:19.003800Z

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

Niklas 2021-05-26T15:07:13.004100Z

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

NoahTheDuke 2021-05-26T15:27:34.005400Z

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

NoahTheDuke 2021-05-26T15:29:55.005800Z

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