Clojure.test / with clojure.test / testing

In clojure.test have a macro that allows you to simultaneously test multiple devices: are.

In clojure.test can I combine a macro arewith testing?

Those. sort of:

(are [scenario expected input]
  (testing scenario
    (= expected (my-fn input)))
    "scenario 1 - replaces -out by -in" "abc-out" "abc-in")
+4
source share
1 answer

This is not possible arein clojure.test ..

I adjusted Stuart Sierra areto support the script testingand error message as follows:

(defmacro my-are
  [scenario fail-msg argv expr & args]
  (if (or
       (and (empty? argv) (empty? args))
       (and (pos? (count argv))
            (pos? (count args))
            (zero? (mod (count args) (count argv)))))
    `(testing ~scenario
       (clojure.template/do-template ~argv (is ~expr ~fail-msg) ~@args))
    (throw (IllegalArgumentException. "The number of args doesn't match are argv."))))

Now the tests are completed in the script testingand error messages are added.

This macro can be used as follows:

(deftest my-test
  (my-are "Scenario 1: testing arithmetic" "Testing my stuff failed" 
          [x y] (= x y)
          2 (- 4 1)
          4 (* 2 2)
          5 (/ 10 2)))

It leads to:



1
3- , 1
1



1 :


1:


: (= 2 (- 4 1))
actual: (not (= 2 3))

, , ( " ) , , (" 1: ").

+1

Source: https://habr.com/ru/post/1657190/


All Articles