A BDD testing framework.
In short: Tests are defined with defdescribe
, suites (groups of nested suites and test cases) are defined with describe
, test cases are defined with it
, and assertions are defined with expect
but can be any function that throws an exception on failure. When lazytest.main/run
is called, all loaded namespaces are checked for tests, and the contained test cases are run (with suites providing context and additional documentation).
Hooks can be used in :context
metadata on suites, and assertion helpers can be used in test cases.
For more information, please check the README.md
.
Test definition vars:
expect
: Create an assertion. Throws if expression returns logical false.it
: Creates a test case, which runs arbitrary code. If the code throws, it's considered a failing test. Otherwise, it's considered a passing test.expect-it
: Combination of expect
and it
to assert a single expression.describe
: Creates a test suite, which is a collection of test cases or other test suites.defdescribe
: Defines a var containing a test suite.Test definition aliases:
Hook vars:
before
, after
: Runs arbitrary code once before (or after) all nested suites and test cases.before-each
, after-each
: Runs arbitrary code before (or after) each nested test case.around
: Run a function taking a single arg, with the arg being a function executing the nested suites or test cases. Useful for binding
(or similar) callsset-ns-context!
: Add hooks to the namespace suite, instead of to a test suite.Assertion helper vars:
throws?
: Calls given no-arg function, returns true if it throws expected class.throws-with-msg?
: Calls given function with no arguments, returns true if it throw expected class and message matches given regex.causes?
: Calls given no-arg function, returns true if it throws expected class anywhere in the cause chain.causes-with-msg?
: Calls given no-arg function, returns true if it throws expected class anywhere in the cause chain and the cause's message matches given regex.ok?
: Calls given no-arg function, returns true if no exception is thrown. (Useful for ignoring logical false return values.)A BDD testing framework. In short: Tests are defined with [[defdescribe]], suites (groups of nested suites and test cases) are defined with [[describe]], test cases are defined with [[it]], and assertions are defined with [[expect]] but can be any function that throws an exception on failure. When `lazytest.main/run` is called, all loaded namespaces are checked for tests, and the contained test cases are run (with suites providing context and additional documentation). Hooks can be used in `:context` metadata on suites, and assertion helpers can be used in test cases. For more information, please check the `README.md`. Test definition vars: * [[expect]]: Create an assertion. Throws if expression returns logical false. * [[it]]: Creates a test case, which runs arbitrary code. If the code throws, it's considered a failing test. Otherwise, it's considered a passing test. * [[expect-it]]: Combination of [[expect]] and [[it]] to assert a single expression. * [[describe]]: Creates a test suite, which is a collection of test cases or other test suites. * [[defdescribe]]: Defines a var containing a test suite. Test definition aliases: * [[should]]: Alias for [[expect]]. * [[specify]]: Alias for [[it]]. * [[context]]: Alias for [[describe]]. Hook vars: * [[before]], [[after]]: Runs arbitrary code once before (or after) all nested suites and test cases. * [[before-each]], [[after-each]]: Runs arbitrary code before (or after) each nested test case. * [[around]]: Run a function taking a single arg, with the arg being a function executing the nested suites or test cases. Useful for `binding` (or similar) calls * [[set-ns-context!]]: Add hooks to the namespace suite, instead of to a test suite. Assertion helper vars: * [[throws?]]: Calls given no-arg function, returns true if it throws expected class. * [[throws-with-msg?]]: Calls given function with no arguments, returns true if it throw expected class and message matches given regex. * [[causes?]]: Calls given no-arg function, returns true if it throws expected class anywhere in the cause chain. * [[causes-with-msg?]]: Calls given no-arg function, returns true if it throws expected class anywhere in the cause chain and the cause's message matches given regex. * [[ok?]]: Calls given no-arg function, returns true if no exception is thrown. (Useful for ignoring logical false return values.)
EXPERIMENTAL. COULD BE CHANGED AT ANY TIME. Please share usage reports at https://github.com/noahtheduke/lazytest/issues
An adaption of the built-in clojure.test
framework. testing
works the same way as clojure.test/testing
, so it does not support metadata selection like lazytest.core/describe
.
Supported clojure.test
vars:
Example:
(ns noahtheduke.example-test
(:require
[lazytest.experimental.interfaces.clojure-test :refer [deftest are is testing]]))
(deftest deftest-test
(is true "expect works inside")
(testing "testing works"
(is (= 7 (+ 3 4)) "is works"))
(testing "are works"
(are [x y] (= x y)
2 (+ 1 1)
4 (* 2 2))))
EXPERIMENTAL. COULD BE CHANGED AT ANY TIME. Please share usage reports at https://github.com/noahtheduke/lazytest/issues An adaption of the built-in `clojure.test` framework. [[testing]] works the same way as `clojure.test/testing`, so it does not support metadata selection like [[lazytest.core/describe]]. Supported `clojure.test` vars: * [[deftest]] * [[testing]] * [[is]] * [[are]] Example: ```clojure (ns noahtheduke.example-test (:require [lazytest.experimental.interfaces.clojure-test :refer [deftest are is testing]])) (deftest deftest-test (is true "expect works inside") (testing "testing works" (is (= 7 (+ 3 4)) "is works")) (testing "are works" (are [x y] (= x y) 2 (+ 1 1) 4 (* 2 2)))) ```
EXPERIMENTAL. COULD BE CHANGED AT ANY TIME. Please share usage reports at https://github.com/noahtheduke/lazytest/issues.
An adaption of the Midje framework. Only adapts the fact
and facts
macros. fact
acts like lazytest.core/it
for the purposes of test-cases.
Unlike Midje, facts
is not an alias for fact
, and fact
not support the (given => expected)
syntax as that's highly complex and outside the scope of this namespace.
prep-ns-suite!
must be called before facts
, as they expect :lazytest/ns-suite
to point to an existing suite.
Example:
(ns noahtheduke.example-test
(:require
[lazytest.experimental.interfaces.midje :refer [prep-ns-suite! facts fact]]))
(prep-ns-suite!)
(facts "a simple top level test"
(fact "a test case"
(expect true "expect works inside"))
(facts "a nested facts call"
(fact "this still works"
(expect true))))
EXPERIMENTAL. COULD BE CHANGED AT ANY TIME. Please share usage reports at <https://github.com/noahtheduke/lazytest/issues>. An adaption of the [Midje](https://github.com/marick/midje) framework. Only adapts the [[fact]] and [[facts]] macros. [[fact]] acts like [[lazytest.core/it]] for the purposes of test-cases. Unlike Midje, [[facts]] is not an alias for [[fact]], and [[fact]] not support the `(given => expected)` syntax as that's highly complex and outside the scope of this namespace. [[prep-ns-suite!]] must be called before [[facts]], as they expect `:lazytest/ns-suite` to point to an existing suite. Example: ```clojure (ns noahtheduke.example-test (:require [lazytest.experimental.interfaces.midje :refer [prep-ns-suite! facts fact]])) (prep-ns-suite!) (facts "a simple top level test" (fact "a test case" (expect true "expect works inside")) (facts "a nested facts call" (fact "this still works" (expect true)))) ```
EXPERIMENTAL. COULD BE CHANGED AT ANY TIME. Please share usage reports at https://github.com/noahtheduke/lazytest/issues.
An adaption of the QUnit framework. Only adapts the unnested style as the nested style can be achieved natively with lazytest.core
macros.
prep-ns-suite!
must be called before module!
or test!
, as they expect :lazytest/ns-suite
to point to an existing suite.
Example:
(ns noahtheduke.example-test
(:require
[lazytest.interfaces.qunit :refer [prep-ns-suite! module! test! assert!]]))
(prep-ns-suite!)
(module! "Group A")
(test! "foo"
(assert! (true? (pos? 1)))
(assert! (false? (pos? 0)) "Expected to be false"))
EXPERIMENTAL. COULD BE CHANGED AT ANY TIME. Please share usage reports at <https://github.com/noahtheduke/lazytest/issues>. An adaption of the [QUnit](https://qunitjs.com/) framework. Only adapts the unnested style as the nested style can be achieved natively with [[lazytest.core]] macros. [[prep-ns-suite!]] must be called before [[module!]] or [[test!]], as they expect `:lazytest/ns-suite` to point to an existing suite. Example: ```clojure (ns noahtheduke.example-test (:require [lazytest.interfaces.qunit :refer [prep-ns-suite! module! test! assert!]])) (prep-ns-suite!) (module! "Group A") (test! "foo" (assert! (true? (pos? 1))) (assert! (false? (pos? 0)) "Expected to be false")) ```
EXPERIMENTAL. COULD BE CHANGED AT ANY TIME. Please share usage reports at https://github.com/noahtheduke/lazytest/issues.
An adaption of the xUnit style of test frameworks. A fairly simple aliasing of the lazytest.core
macros:
lazytest.core/defdescribe
-> defsuite
lazytest.core/describe
-> suite
lazytest.core/it
-> test-case
lazytest.core/expect
-> assert!
Example:
(ns noahtheduke.example-test
(:require
[lazytest.experimental.interfaces.xunit :refer [defsuite suite test-case assert!]]))
(defsuite defsuite-test
(suite "defsuite works"
(assert! true "expect works inside"))
(suite "suite works"
(test-case "test-case works"
(assert! true))))
EXPERIMENTAL. COULD BE CHANGED AT ANY TIME. Please share usage reports at <https://github.com/noahtheduke/lazytest/issues>. An adaption of the [xUnit](https://en.wikipedia.org/wiki/XUnit) style of test frameworks. A fairly simple aliasing of the [[lazytest.core]] macros: * [[lazytest.core/defdescribe]] -> [[defsuite]] * [[lazytest.core/describe]] -> [[suite]] * [[lazytest.core/it]] -> [[test-case]] * [[lazytest.core/expect]] -> [[assert!]] Example: ```clojure (ns noahtheduke.example-test (:require [lazytest.experimental.interfaces.xunit :refer [defsuite suite test-case assert!]])) (defsuite defsuite-test (suite "defsuite works" (assert! true "expect works inside")) (suite "suite works" (test-case "test-case works" (assert! true)))) ```
Adapts Expectations v2 (https://github.com/clojure-expectations/clojure-test) to Lazytest.
Adapts Expectations v2 (https://github.com/clojure-expectations/clojure-test) to Lazytest.
Command-line test launcher.
Command-line test launcher.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close