added more doc
This commit is contained in:
parent
43711f902f
commit
a995c0c223
2 changed files with 55 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -5,3 +5,4 @@
|
||||||
target
|
target
|
||||||
pom.xml
|
pom.xml
|
||||||
/src
|
/src
|
||||||
|
pom.xml.asc
|
||||||
|
|
|
@ -14,6 +14,60 @@
|
||||||
; See the License for the specific language governing permissions and
|
; See the License for the specific language governing permissions and
|
||||||
; limitations under the License.
|
; limitations under the License.
|
||||||
(ns data-test
|
(ns data-test
|
||||||
|
^{:author "Michael Jerger, with contributions and suggestions by razum2um",
|
||||||
|
:doc "data-test separates test data from test code and allows a
|
||||||
|
more data driven approach for testing. In case of having huge amounts
|
||||||
|
of test-input & -expectations your test code will remain readable and concise.
|
||||||
|
data-test is founded on and compatible with `clojure.test`. Integration in your
|
||||||
|
test environments will work without any changes. For explicit, intentful and
|
||||||
|
obvious data, data-test uses aero (see: https://github.com/juxt/aero).
|
||||||
|
|
||||||
|
USAGE
|
||||||
|
Define your data test similar to deftest and express your test e.g. with
|
||||||
|
is macro. The given binding [input expected] will let symbols which can be
|
||||||
|
used in your test code.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
(ns my.cool.project-test
|
||||||
|
(:require [clojure.test :refer :all]
|
||||||
|
[data-test :refer :all]))
|
||||||
|
|
||||||
|
(defdatatest should-test-multiple-specs [input expected]
|
||||||
|
(is (= input expected)))
|
||||||
|
|
||||||
|
Your test data are loaded as resource and therefore data has to be located in
|
||||||
|
classpath. The path is determined by your tests namespace and your tests
|
||||||
|
definition name. In given case it is
|
||||||
|
|
||||||
|
my/cool/project_test/should_test_multiple_spec.edn
|
||||||
|
|
||||||
|
{:input 1
|
||||||
|
:expected 1}
|
||||||
|
|
||||||
|
The keys :input and :expected are fixed, the values can be anything you need.
|
||||||
|
You can have up to 11 data specifications for each test.
|
||||||
|
|
||||||
|
my/cool/project_test/should_test_multiple_spec.[1-9].edn
|
||||||
|
|
||||||
|
is a valid resource-location also.
|
||||||
|
|
||||||
|
Test can be executed by using
|
||||||
|
|
||||||
|
(clojure.test/run-tests)
|
||||||
|
|
||||||
|
and will produce the usual test-output like:
|
||||||
|
|
||||||
|
Running namespace tests…
|
||||||
|
FAIL in: project_test.clj: 35: should-test-multiple-specs: project_test/should_test_multiple_specs.1.edn:
|
||||||
|
expected: 1
|
||||||
|
|
||||||
|
actual: (2)
|
||||||
|
|
||||||
|
|
||||||
|
4 tests finished, problems found. 😭 errors: 0, failures: 1, ns: 1, vars: 3
|
||||||
|
|
||||||
|
The test data resource used will determine the testing context."}
|
||||||
(:require
|
(:require
|
||||||
[clojure.test :as t]
|
[clojure.test :as t]
|
||||||
[data-test.reporter :as reporter]
|
[data-test.reporter :as reporter]
|
||||||
|
|
Loading…
Reference in a new issue