Compare commits

..

28 commits

Author SHA1 Message Date
cce8376ec3 update readme 2023-08-02 14:10:58 +02:00
0d2eb27163 Merge branch 'master' of ssh://repo.prod.meissa.de:2222/meissa/data-test 2023-07-28 14:48:05 +02:00
bf696abe74 [Skip-CI] Add Development and mirrors section 2023-07-28 14:47:55 +02:00
cd29fb0a6d Merge branch 'master' of ssh://repo.prod.meissa.de:2222/meissa/data-test 2023-07-28 08:44:28 +02:00
fb08a1e45a update readme 2022-12-27 07:50:20 +01:00
ba35b89f8c
Famous last words 2022-12-23 14:21:13 +01:00
Jan Krebs
944d7ef857 Update copyright year 2021-06-29 10:15:41 +02:00
jem
78116ced9a update doc 2019-10-11 17:04:17 +02:00
jem
972a220ab3 Version 0.1.2-SNAPSHOT 2019-10-11 13:27:24 +02:00
jem
bdc82c1bc2 Version 0.1.1 2019-10-11 13:27:03 +02:00
jem
8b56e89782 fixed tests with completly activated schema validation 2019-10-11 13:26:24 +02:00
jem
041bf20426 add mastodon link 2019-07-22 17:50:31 +02:00
jem
9d92ff6ea0 add mastodon-link 2019-07-22 17:33:12 +02:00
jem
b202a07c25 add some idea for meta handling ... 2019-06-19 09:10:23 +02:00
jem
f084e5d6c0 improve exception handling for aero issues 2019-06-06 08:47:33 +02:00
jem
c3403158c2 add refactoring example 2019-06-06 08:40:26 +02:00
jem
2420131780 sometimes meta is a good idea 2019-06-05 08:53:25 +02:00
jem
a995c0c223 added more doc 2019-05-31 14:23:24 +02:00
jem
43711f902f Version 0.1.1-SNAPSHOT 2019-05-31 14:06:42 +02:00
jem
53c711a65e Version 0.1.0 2019-05-31 14:06:19 +02:00
jem
c5bdf3ba1b remove unused deps 2019-05-31 14:03:51 +02:00
jem
512600a86f added reference 2019-05-31 13:56:29 +02:00
jem
feb56750ea fix ignore 2019-05-31 13:56:12 +02:00
jem
51706c67c1 adjust resource name to convention 2019-05-31 13:55:55 +02:00
jem
6d4d60fe84 ignore unused 2019-05-31 13:54:55 +02:00
jem
f78d07a824 add first doc 2019-05-31 13:10:46 +02:00
jem
34aefea0c3 added subcomponents 2019-05-31 11:22:57 +02:00
cf62e4f386
Merge pull request #1 from DomainDrivenArchitecture/specify-search-places
Specify search places in error
2019-05-31 08:16:23 +02:00
15 changed files with 234 additions and 139 deletions

3
.gitignore vendored
View file

@ -1,5 +1,8 @@
.lein* .lein*
.nrepl* .nrepl*
.cpcache .cpcache
.vscode
target target
pom.xml pom.xml
/src
pom.xml.asc

127
README.md
View file

@ -1,8 +1,131 @@
# data-test # data-test
[![Clojars Project](https://img.shields.io/clojars/v/dda/data-test.svg)](https://clojars.org/dda/data-test) [![Clojars Project](https://img.shields.io/clojars/v/dda/data-test.svg)](https://clojars.org/dda/data-test)
[![Build Status](https://travis-ci.org/DomainDrivenArchitecture/data-test.svg?branch=master)](https://travis-ci.org/DomainDrivenArchitecture/data-test) [![Build Status](https://travis-ci.org/DomainDrivenArchitecture/data-test.svg?branch=master)](https://travis-ci.org/DomainDrivenArchitecture/data-test)
[![Slack](https://img.shields.io/badge/chat-clojurians-green.svg?style=flat)](https://clojurians.slack.com/messages/#dda-pallet/) | [<img src="https://domaindrivenarchitecture.org/img/meetup.svg" width=50 alt="DevOps Hacking with Clojure Meetup"> DevOps Hacking with Clojure](https://www.meetup.com/de-DE/preview/dda-pallet-DevOps-Hacking-with-Clojure) | [Website & Blog](https://domaindrivenarchitecture.org) [![Slack](https://img.shields.io/badge/chat-clojurians-green.svg?style=flat)](https://clojurians.slack.com/messages/#dda-pallet/) | [<img src="https://meissa-gmbh.de/img/community/Mastodon_Logotype.svg" width=20 alt="team@social.meissa-gmbh.de"> team@social.meissa-gmbh.de](https://social.meissa-gmbh.de/@team) | [Website & Blog](https://domaindrivenarchitecture.org)
## About
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](https://github.com/juxt/aero).
## Usage
Import data-test to your project
```clojure
[dda/data-test "0.1.1"]
```
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.
```clojure
(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`:
```clojure
{: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:
```console
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)
framework for data-driven tests 4 tests finished, problems found. 😭 errors: 0, failures: 1, ns: 1, vars: 3
```
The test data resource used will determine the testing context.
As we are eating our own dog-food, we refactored our test and are using data-test. An example for refactoring you can find in our [dda-serverspec](https://github.com/DomainDrivenArchitecture/dda-serverspec-crate/commit/43abadbdb96afde6b1dc85834e465ee61eb464d2).
## Reference
### Loading Resources
data-test tries to locate data files on classpath as resource - should work similar in jar-files and in filesystem classpaths. The resource locations are determined by test namespace (e.g. `my/cool/project_test`) and defined test name (e.g. `should_test_multiple_spec.edn`). Resource-naming is following clojures usual filesystem mapping conventions.
```console
my/cool/project_test/should_test_multiple_spec.edn
my/cool/project_test/should_test_multiple_spec.1.edn
...
my/cool/project_test/should_test_multiple_spec.9.edn
```
A test is executed for every file defined.
### Bindings
`defdatatest name [binding-for-input binding-for-expected]` is translated in sth. like:
```clojure
(deftest should-test-with-data-explicit-version
(let [testdata (loader/read-test-data-spec (io/resource "data_test_test/should_test_with_data_explicit_version.edn"))
{:keys [input expected]} testdata]
(is (= expected
input))))
```
As you can see, input and expected can be used in your test code. You have to declare the used symbols in the binding section.
### Resources with AERO
You can use [aero](https://github.com/juxt/aero) in your test data declaration, e.g.
```clojure
{:references {:to-be-refernced "ref-test"}
:input #ref [:references :to-be-refernced]
:expected #ref [:references :to-be-refernced]}
```
### Adding Meta
You can add some metadata to your data files, e.g.
```clojure
{:input some-data
:expected some-data
:meta {:name "name of data"
:description "describe what testcase is represented by this piec of data"
:link "https://add-some-link-here"}}
```
### Generated Output
Each data-test execution will report it's results to "target/datatest/". The key `:test-event` reflect [clojure.test reporting events](https://github.com/clojure/clojure/blob/8c402a8c9695a4eddc07cbbe0d95d44e1372f0bf/src/clj/clojure/test.clj#L214), the key `:test-data-spec` reflects the used data-test data specification.
```clojure
(def TestDataReport
{:test-event s/Any
:test-data-spec {:input s/Any
:expected s/Any
:data-spec-file s/Str}})
```
## Development & mirrors
Development happens at: https://repo.prod.meissa.de/meissa/data-test
Mirrors are:
* https://gitlab.com/domaindrivenarchitecture/data-test (CI issues and PR)
* https://github.com/DomainDrivenArchitecture/data-test
## License
Copyright © 2022 meissa GmbH
Licensed under the [Apache License, Version 2.0](LICENSE) (the "License")
Pls. find licenses of our subcomponents [here](doc/SUBCOMPONENT_LICENSE)

View file

@ -5,8 +5,13 @@ separate copyright notices and license terms. Your use of the source
code for the these subcomponents is subject to the terms and code for the these subcomponents is subject to the terms and
conditions of the following licenses. conditions of the following licenses.
lein with-profile uberjar licenses lein licenses
org.clojure/test.check - 0.10.0-alpha3 - Eclipse Public License 1.0
aero - 1.1.3 - The MIT License
org.clojure/core.specs.alpha - 0.2.44 - Eclipse Public License 1.0
prismatic/schema - 1.1.10 - Eclipse Public License
org.clojure/spec.alpha - 0.2.176 - Eclipse Public License 1.0
@ -98,112 +103,3 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-------------------------------------------------------------------------------
The BSD 3-Clause License The following is a BSD 3-Clause ("BSD New" or "BSD Simplified") license template. To generate your own license, change the values of OWNER, ORGANIZATION and YEAR from their original values as given here, and substitute your own.
Note: You may omit clause 3 and still be OSD-conformant. Despite its colloquial name "BSD New", this is not the newest version of the BSD license; it was followed by the even newer BSD-2-Clause version, sometimes known as the "Simplified BSD License". On January 9th, 2008 the OSI Board approved BSD-2-Clause, which is used by FreeBSD and others. It omits the final "no-endorsement" clause and is thus roughly equivalent to the MIT License.
Historical Background: The original license used on BSD Unix had four clauses. The advertising clause (the third of four clauses) required you to acknowledge use of U.C. Berkeley code in your advertising of any product using that code. It was officially rescinded by the Director of the Office of Technology Licensing of the University of California on July 22nd, 1999. He states that clause 3 is "hereby deleted in its entirety." The four clause license has not been approved by OSI. The license below does not contain the advertising clause.
This prelude is not part of the license.
OWNER = Regents of the University of California
ORGANIZATION = University of California, Berkeley
YEAR = 1998
In the original BSD license, both occurrences of the phrase "COPYRIGHT HOLDERS AND CONTRIBUTORS" in the disclaimer read "REGENTS AND CONTRIBUTORS".
License template
Copyright (c) $YEAR $OWNER, All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
------------------------------------------------------------------------------
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright © 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, “this License” refers to version 3 of the GNU Lesser General Public License, and the “GNU GPL” refers to version 3 of the GNU General Public License.
“The Library” refers to a covered work governed by this License, other than an Application or a Combined Work as defined below.
An “Application” is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library.
A “Combined Work” is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the “Linked Version”.
The “Minimal Corresponding Source” for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version.
The “Corresponding Application Code” for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version:
a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following:
a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license document.
c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.
1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version.
e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.
------------------------------------------------------------------------------
License
Copyright (c) 2000 - 2018 The Legion of the Bouncy Castle Inc. (https://www.bouncycastle.org)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -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]

View file

@ -21,9 +21,14 @@
[aero.core :as aero])) [aero.core :as aero]))
;TODO: replace schema with spec ;TODO: replace schema with spec
;TODO: try out ^ for meta ...
(def TestDataSpec (def TestDataSpec
{:input s/Any {:input s/Any
:expected s/Any}) :expected s/Any
(s/optional-key :meta) {(s/optional-key :name) s/Str
(s/optional-key :description) s/Str
(s/optional-key :link) s/Str}
(s/optional-key :references) s/Any})
(def RuntimeTestDataSpec (def RuntimeTestDataSpec
(merge (merge
@ -34,8 +39,8 @@
[runtime-test-data-spec :- RuntimeTestDataSpec] [runtime-test-data-spec :- RuntimeTestDataSpec]
(:data-spec-file runtime-test-data-spec)) (:data-spec-file runtime-test-data-spec))
(s/defn read-test-data-spec :- TestDataSpec (s/defn read-test-data-spec ; :- TestDataSpec - at least TestDataSpec but more keys are allowed
[resource-url :- s/Str] [resource-url] ; input is a url object
(aero/read-config resource-url)) (aero/read-config resource-url))
(s/defn data-test-spec-file-prefix :- s/Str (s/defn data-test-spec-file-prefix :- s/Str
@ -52,7 +57,7 @@
(map #(str prefix "." % ".edn") (map #(str prefix "." % ".edn")
(range 10))))) (range 10)))))
(s/defn load-data-test-spec :- RuntimeTestDataSpec (s/defn load-data-test-spec ; either :- RuntimeTestDataSpec or nil
[file-path :- s/Str] [file-path :- s/Str]
(let [file-resource (io/resource file-path)] (let [file-resource (io/resource file-path)]
(when file-resource (when file-resource
@ -60,7 +65,7 @@
{:data-spec-file file-path} {:data-spec-file file-path}
(read-test-data-spec file-resource))))) (read-test-data-spec file-resource)))))
(s/defn load-data-test-specs :- [RuntimeTestDataSpec] (s/defn load-data-test-specs ; :- [RuntimeTestDataSpec] at least but more keys are allowed in elements
[name-key :- s/Keyword] [name-key :- s/Keyword]
(let [locations (data-test-spec-file-names name-key) (let [locations (data-test-spec-file-names name-key)
data-test-specs (filter some? (map load-data-test-spec locations))] data-test-specs (filter some? (map load-data-test-spec locations))]

View file

@ -1,4 +1,4 @@
(defproject dda/data-test "0.1.0-SNAPSHOT" (defproject dda/data-test "0.1.2-SNAPSHOT"
:description "a data driven testing framework." :description "a data driven testing framework."
:url "https://domaindrivenarchitecture.org" :url "https://domaindrivenarchitecture.org"
:license {:name "Apache License, Version 2.0" :license {:name "Apache License, Version 2.0"
@ -15,18 +15,14 @@
:lein-tools-deps/config {:config-files [:install :user :project]} :lein-tools-deps/config {:config-files [:install :user :project]}
:profiles {:dev {:source-paths ["test/src"] :profiles {:dev {:source-paths ["test/src"]
:resource-paths ["test/resources"] :resource-paths ["test/resources"]
:dependencies :dependencies []
[[org.clojure/test.check "0.10.0-alpha3"]
;[expectations "2.2.0-SNAPSHOT"]
]
:leiningen/reply :leiningen/reply
{:dependencies [[org.slf4j/jcl-over-slf4j "1.8.0-beta0"]] {:dependencies [[org.slf4j/jcl-over-slf4j "1.8.0-beta0"]]
:exclusions [commons-logging]} :exclusions [commons-logging]}
} }
:test {:test-paths ["test/src"] :test {:test-paths ["test/src"]
:resource-paths ["test/resources"] :resource-paths ["test/resources"]
:dependencies [;[expectations "2.2.0-SNAPSHOT"] :dependencies []}}
]}}
:release-tasks [["vcs" "assert-committed"] :release-tasks [["vcs" "assert-committed"]
["change" "version" "leiningen.release/bump-version" "release"] ["change" "version" "leiningen.release/bump-version" "release"]
["vcs" "commit"] ["vcs" "commit"]

View file

@ -0,0 +1,5 @@
{:simple "test"
:not-working-list '(1 2 3
4 5
6 7
8)}

View file

@ -1 +1,2 @@
{:test "data1"} {:input "data1"
:expectation true}

View file

@ -1 +1,2 @@
{:test "data9"} {:input "data9"
:expectation true}

View file

@ -1 +1,2 @@
{:test "data"} {:input "data"
:expectation true}

View file

@ -1 +1,2 @@
{:simple "test"} {:input "test"
:expected true}

View file

@ -1,3 +1,3 @@
{:to-be-refernced "ref-test" {:references {:to-be-refernced "ref-test"}
:key1 #ref [:to-be-refernced] :input #ref [:references :to-be-refernced]
:key2 #ref [:to-be-refernced]} :expected #ref [:references :to-be-refernced]}

View file

@ -20,11 +20,13 @@
[data-test.loader :as sut])) [data-test.loader :as sut]))
(deftest should-read-test-data-spec (deftest should-read-test-data-spec
(is (= {:simple "test"} (is (= {:input "test"
:expected true}
(sut/read-test-data-spec (io/resource "simple_aero.edn")))) (sut/read-test-data-spec (io/resource "simple_aero.edn"))))
(is (= {:to-be-refernced "ref-test", :key1 "ref-test", :key2 "ref-test"} (is (= {:references {:to-be-refernced "ref-test"}, :input "ref-test", :expected "ref-test"}
(sut/read-test-data-spec (io/resource "tagged_aero.edn")))) (sut/read-test-data-spec (io/resource "tagged_aero.edn"))))
) (is (thrown? RuntimeException
(sut/read-test-data-spec (io/resource "aero_with_deserialization_issue.edn")))))
(deftest should-calculate-data-test-spec-file-prefix (deftest should-calculate-data-test-spec-file-prefix
(is (= "data_test/loader_test/test_it" (is (= "data_test/loader_test/test_it"
@ -45,7 +47,8 @@
(sut/data-test-spec-file-names ::test-it)))) (sut/data-test-spec-file-names ::test-it))))
(deftest should-load-data (deftest should-load-data
(is (= {:test "data" (is (= {:input "data"
:expectation true
:data-spec-file "data_test/loader_test/test_it.edn"} :data-spec-file "data_test/loader_test/test_it.edn"}
(sut/load-data-test-spec (str (sut/data-test-spec-file-prefix ::test-it) ".edn"))))) (sut/load-data-test-spec (str (sut/data-test-spec-file-prefix ::test-it) ".edn")))))
@ -54,11 +57,14 @@
(sut/load-data-test-spec (str (sut/data-test-spec-file-prefix ::not-existing) ".edn"))))) (sut/load-data-test-spec (str (sut/data-test-spec-file-prefix ::not-existing) ".edn")))))
(deftest should-load-data-test-specs (deftest should-load-data-test-specs
(is (= [{:test "data" (is (= [{:input "data"
:expectation true
:data-spec-file "data_test/loader_test/test_it.edn"} :data-spec-file "data_test/loader_test/test_it.edn"}
{:test "data1" {:input "data1"
:expectation true
:data-spec-file "data_test/loader_test/test_it.1.edn"} :data-spec-file "data_test/loader_test/test_it.1.edn"}
{:test "data9" {:input "data9"
:expectation true
:data-spec-file "data_test/loader_test/test_it.9.edn"}] :data-spec-file "data_test/loader_test/test_it.9.edn"}]
(sut/load-data-test-specs ::test-it)))) (sut/load-data-test-specs ::test-it))))

View file

@ -17,12 +17,15 @@
(:require (:require
[clojure.test :refer :all] [clojure.test :refer :all]
[clojure.java.io :as io] [clojure.java.io :as io]
[schema.core :as s]
[data-test.loader :as loader] [data-test.loader :as loader]
[data-test :as sut])) [data-test :as sut]))
(s/set-fn-validation! true)
; -------------------- explicit version ------------------ ; -------------------- explicit version ------------------
(deftest should-test-with-data-explicit-version (deftest should-test-with-data-explicit-version
(let [testdata (loader/read-test-data-spec (io/resource "data_test_test/should-test-with-data-explicit-version.edn")) (let [testdata (loader/read-test-data-spec (io/resource "data_test_test/should_test_with_data_explicit_version.edn"))
{:keys [input expected]} testdata] {:keys [input expected]} testdata]
(is (= expected (is (= expected
input)))) input))))