воскресенье, 2 апреля 2017 г.

clojure.test tutorial

(ns example.basic-types-tests
  (:gen-class)
  (:require [clojure.test :refer [deftest testing is use-fixtures]]
            [example.basic-types :as basic]
            [clojure.spec :as s]
            [clojure.spec.gen :as gen]))


(defn once-fixture [f]
  (println "Prepare for for all tests...")
  (f)
  (println "Clean up after all tests..."))

(defn before-any-test-fixture [f]
  (println "Next test preparation...")
  (f)
  (println "Clean up after test..."))

(use-fixtures :once once-fixture)
(use-fixtures :each before-any-test-fixture)

(deftest basic-types-spec
  (testing "testing basic types spec"
    (is (= 1 1))))

(deftest basic-types-generator-test
  (testing "testing generators for basic types"
    (is (= 1000 (count (gen/sample (s/gen ::basic/string) 1000))))))

(deftest arithmetic-test
  (testing "this should throw exception"
    (is (thrown? ArithmeticException (/ 1 0)))))


;; This will make tests hook: only specified tests will be run.
;; Warining! if hook was installed then only specified tests will be run
;; to disable hook perform (ns-unmap *ns* 'test-ns-hook)
;(defn test-ns-hook []
;  (basic-types-generator-test))

;; To run particular test form some namespace use follwing command in repl:
;;(clojure.test/test-vars [#'example.basic-types-tests/arithmetic-test])
;; if everything ok it returns nil, otherwise returns report. This will run test with existing fixtures
;; or lein test :only my.namespace/my-test

Комментариев нет:

Отправить комментарий