load test-data dynamicaly
This commit is contained in:
parent
dc1055d1c4
commit
21b03e2ef8
4 changed files with 26 additions and 15 deletions
|
@ -31,8 +31,9 @@
|
||||||
|
|
||||||
(defprotocol RunTest
|
(defprotocol RunTest
|
||||||
"Protocol for data driven tests"
|
"Protocol for data driven tests"
|
||||||
|
(name-prefix [dda-test])
|
||||||
(run-test [dda-test])
|
(run-test [dda-test])
|
||||||
(name-prefix [dda-test]))
|
)
|
||||||
|
|
||||||
(s/defn dispatch-by-name :- s/Keyword
|
(s/defn dispatch-by-name :- s/Keyword
|
||||||
"Dispatcher for data-tests."
|
"Dispatcher for data-tests."
|
||||||
|
@ -50,24 +51,27 @@
|
||||||
(aero/read-config resource-url))
|
(aero/read-config resource-url))
|
||||||
|
|
||||||
(s/defn data-file-prefix :- s/Str
|
(s/defn data-file-prefix :- s/Str
|
||||||
[runner :- TestRunner]
|
[name-key :- s/Keyword]
|
||||||
(let [name-key (:name runner)]
|
(str/replace
|
||||||
(str/replace
|
(str/replace (str (namespace name-key) "/" (name name-key))
|
||||||
(str/replace (str (namespace name-key) "/" (name name-key))
|
#"-" "_")
|
||||||
#"-" "_")
|
#"\." "/"))
|
||||||
#"\." "/")))
|
|
||||||
|
(s/defn load-test-data
|
||||||
|
[file-prefix :- s/Str]
|
||||||
|
(let [file-path (str (data-file-prefix file-prefix) ".edn")]
|
||||||
|
(println file-path)
|
||||||
|
(read-data
|
||||||
|
(io/resource file-path))))
|
||||||
|
|
||||||
(extend-type TestRunner
|
(extend-type TestRunner
|
||||||
RunTest
|
RunTest
|
||||||
(name-prefix [_]
|
(name-prefix [_]
|
||||||
(data-file-prefix _))
|
(data-file-prefix (:name _)))
|
||||||
(run-test [_]
|
(run-test [_]
|
||||||
(println (data-file-prefix _))
|
(let [testdata (load-test-data (data-file-prefix (:name _)))
|
||||||
(let [testdata (read-data
|
{:keys [input expectation]} testdata]
|
||||||
(io/resource "data_test_test/should-test-with-data-record-version.edn"))
|
(data-test _ input expectation))))
|
||||||
;(str (data-file-prefix _) ".edn")))
|
|
||||||
{:keys [input expectation]} testdata]
|
|
||||||
(data-test _ input expectation))))
|
|
||||||
|
|
||||||
(defn create-test-runner
|
(defn create-test-runner
|
||||||
[test-name]
|
[test-name]
|
||||||
|
|
1
test/resources/data_test/runner_test/test_it.edn
Normal file
1
test/resources/data_test/runner_test/test_it.edn
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{:test "data"}
|
|
@ -0,0 +1,2 @@
|
||||||
|
{:input 1
|
||||||
|
:expectation 1}
|
|
@ -29,7 +29,11 @@
|
||||||
|
|
||||||
(deftest should-calculate-data-file-prefix
|
(deftest should-calculate-data-file-prefix
|
||||||
(is (= "data_test/runner_test/test_it"
|
(is (= "data_test/runner_test/test_it"
|
||||||
(sut/data-file-prefix (sut/create-test-runner ::test-it)))))
|
(sut/data-file-prefix ::test-it))))
|
||||||
|
|
||||||
|
(deftest should-load-data
|
||||||
|
(is (= {:test "data"}
|
||||||
|
(sut/load-test-data ::test-it))))
|
||||||
|
|
||||||
(s/defmethod sut/data-test ::test-it
|
(s/defmethod sut/data-test ::test-it
|
||||||
[_ input :- s/Any expectation :- s/Any]
|
[_ input :- s/Any expectation :- s/Any]
|
||||||
|
|
Loading…
Reference in a new issue