Liking cljdoc? Tell your friends :D

lazytest.core

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) 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.)
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.)
raw docstring

lazytest.experimental.interfaces.clojure-test

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. To mirror clojure.test, deftest wraps the entire test in a single test-case. testing works the same way as clojure.test/testing, so it does not support metadata selection like lazytest.core/describe. thrown? and thrown-with-msg? must be required to be used as is does not support clojure.test/assert-expr.

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. To mirror `clojure.test`, [[deftest]] wraps the entire test in a single test-case. [[testing]] works the same way as `clojure.test/testing`, so it does not support metadata selection like [[lazytest.core/describe]]. [[thrown?]] and [[thrown-with-msg?]] must be required to be used as [[is]] does not support `clojure.test/assert-expr`.

Supported `clojure.test` vars:
* [[deftest]]
* [[testing]]
* [[is]]
* [[are]]
* [[thrown?]]
* [[thrown-with-msg?]]

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))))
```
raw docstring

lazytest.experimental.interfaces.expectations

EXPERIMENTAL. COULD BE CHANGED AT ANY TIME. Please share usage reports at https://github.com/noahtheduke/lazytest/issues

An adaption of the Clojure library Expectations v2. To mirror how it's built for clojure.test, defexpect wraps the entire test in a single test-case. expecting works the same way as clojure.test/testing, so it does not support metadata selection like lazytest.core/describe. expect is implemented in lazytest.extensions.expectations/expect. None of the utility functions from Expectations v2 are adapted here. They can be found in lazytest.extensions.expectations.

To use just the expect assertion from Expectations v2, please see lazytest.extensions.expectations/expect.

Supported Expectations vars:

Example:

(ns noahtheduke.example-test
  (:require
   [clojure.spec.alpha :as s]
   [lazytest.experimental.interfaces.expectations :refer [defexpect expecting expect]]))

(s/def ::pos pos?)
(defexpect expectations-test
  (expecting "value"
    (expect true))
  (expecting "="
    (expect 1 1))
  (expecting "fn?"
    (let [i 1] (expect pos? i)))
  (expecting "regex"
    (expect #"hello" "hello world"))
  (expecting "instance?"
    (expect String "hello world"))
  (expecting "catch"
    (expect ExceptionInfo (throw (ex-info "aw shucks" {}))))
  (expecting "spec"
    (expect ::pos 1)))
EXPERIMENTAL. COULD BE CHANGED AT ANY TIME. Please share usage reports at https://github.com/noahtheduke/lazytest/issues

An adaption of the Clojure library [Expectations v2](https://github.com/clojure-expectations/clojure-test). To mirror how it's built for `clojure.test`, [[defexpect]] wraps the entire test in a single test-case. [[expecting]] works the same way as `clojure.test/testing`, so it does not support metadata selection like [[lazytest.core/describe]]. [[expect]] is implemented in [[lazytest.extensions.expectations/expect]]. None of the utility functions from Expectations v2 are adapted here. They can be found in [[lazytest.extensions.expectations]].

To use just the `expect` assertion from Expectations v2, please see [[lazytest.extensions.expectations/expect]].

Supported Expectations vars:
* [[defexpect]]
* [[expecting]]
* [[expect]]
* [[in]]
* [[from-each]]
* [[more]]
* [[more-of]]
* [[more->]]

Example:
```clojure
(ns noahtheduke.example-test
  (:require
   [clojure.spec.alpha :as s]
   [lazytest.experimental.interfaces.expectations :refer [defexpect expecting expect]]))

(s/def ::pos pos?)
(defexpect expectations-test
  (expecting "value"
    (expect true))
  (expecting "="
    (expect 1 1))
  (expecting "fn?"
    (let [i 1] (expect pos? i)))
  (expecting "regex"
    (expect #"hello" "hello world"))
  (expecting "instance?"
    (expect String "hello world"))
  (expecting "catch"
    (expect ExceptionInfo (throw (ex-info "aw shucks" {}))))
  (expecting "spec"
    (expect ::pos 1)))
```
raw docstring

lazytest.experimental.interfaces.midje

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))))
```
raw docstring

lazytest.experimental.interfaces.qunit

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"))
```
raw docstring

lazytest.experimental.interfaces.xunit

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:

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))))
```
raw docstring

lazytest.extensions.expectations

Adapts the expect assertion and utility functions from Expectations v2.

note

As of Lazytest 1.7.0, the interface vars defexpect and expecting have been marked as deprecated and will be removed in a future version. Please require them from lazytest.experimental.interfaces.expectations if you wish to continue to use them, tho take care with them being implemented to match their original behavior.

The Expectations v2 interface vars (defexpect, expecting, etc) have also been adapted. Due to the differences in Lazytest and clojure.test, test cases must be defined with lazytest.core/it, as expect is merely an assertion.

(defexpect example-test
  (expecting "many ways to work"
    (it "is a cool assertion DSL"
      (expect 2 2))))
Adapts the `expect` assertion and utility functions from [Expectations v2](https://github.com/clojure-expectations/clojure-test).

> [!NOTE]
> As of Lazytest 1.7.0, the interface vars [[defexpect]] and [[expecting]] have been marked as deprecated and _will_ be removed in a future version. Please require them from [[lazytest.experimental.interfaces.expectations]] if you wish to continue to use them, tho take care with them being implemented to match their original behavior.

The Expectations v2 interface vars (`defexpect`, `expecting`, etc) have also been adapted. Due to the differences in Lazytest and `clojure.test`, test cases must be defined with `lazytest.core/it`, as [[expect]] is merely an assertion.

```clojure
(defexpect example-test
  (expecting "many ways to work"
    (it "is a cool assertion DSL"
      (expect 2 2))))
```
raw docstring

lazytest.main

Command-line test launcher.

Command-line test launcher.
raw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close