package tezt

  1. Overview
  2. Docs
Test framework for unit tests, integration tests, and regression tests

Install

Dune Dependency

Authors

Maintainers

Sources

tezt-3.1.0.tar.bz2
md5=d395cb9e663635ea8795f47c9bd9249f
sha512=d7c62899684ec202a98669eb575a2dc3bd1f8cf0430447c789a9d0aadc04a611d0dcfbcd7d61c613d4b7c78fd1bc4c533e4fcb48dbc8e3f19feaabe4ddd78723

Description

Published: 05 Apr 2023

README

Tezt

Tezt (pronounced "tezty", as in "tasty" with a "z") is a test framework for OCaml. It is well suited for writing and executing unit, integration and regression tests. It integrates well with continuous integration (CI).

API Documentation

The API documentation contains an introduction to Tezt as well as documentation for all modules. It is generated from lib/tezt.ml.

Getting Started

Install

Install with opam:

opam install tezt

Write a Test

Create a file such as test/main.ml:

(* [Tezt] and its submodule [Base] are designed to be opened.
   [Tezt] is the main module of the library and it only contains submodules,
   such as [Test] which is used below.
   [Tezt.Base] contains values such as [unit] which is used below. *)
open Tezt
open Tezt.Base

(* Register as many tests as you want like this. *)
let () =
  Test.register
    (* [~__FILE__] contains the name of the file in which the test is defined.
       It allows to select tests to run based on their filename. *)
    ~__FILE__
    (* Titles uniquely identify tests so that they can be individually selected. *)
    ~title: "demo"
    (* Tags are another way to group tests together to select them. *)
    ~tags: [ "math"; "addition" ]
  @@ fun () ->
  (* Here is the actual test. *)
  if 1 + 1 <> 2 then Test.fail "expected 1 + 1 = 2, got %d" (1 + 1);
  (* Here is another way to write the same test. *)
  Check.((1 + 1 = 2) int) ~error_msg: "expected 1 + 1 = %R, got %L";
  Log.info "Math is safe today.";
  (* [unit] is [Lwt.return ()]. *)
  unit

(* Call the main function of Tezt so that it actually runs your tests. *)
let () = Test.run ()

Then create a test/dune file:

(test (name main) (libraries tezt))

You can now run your test with dune runtest. However dune runtest is limited because you cannot pass command-line arguments. Usually, you would instead run something like:

dune exec test/main.exe -- -i

This should show you:

[09:04:06.395] Math is safe today.
[09:04:06.395] [SUCCESS] (1/1) demo

The -i flag is a short-hand for --info and sets the log level so that you can see the result of the call to Log.info.

To see the list of command-line options, in particular how to select tests from the command-line, how to run them in parallel and how to produce reports, run:

dune exec test/main.exe -- --help

Dependencies (6)

  1. ezjsonm >= "1.1.0"
  2. base-unix
  3. lwt >= "5.6.0"
  4. re >= "1.7.2"
  5. ocaml >= "4.12"
  6. dune >= "3.0"

Dev Dependencies (5)

  1. ocamlformat with-test & = "0.21.0"
  2. conf-npm with-test
  3. js_of_ocaml-lwt with-test
  4. js_of_ocaml with-test
  5. conf-npm with-test

Used by (46)

  1. bam
  2. dedukti >= "2.7"
  3. octez-alcotezt < "18.0"
  4. octez-bls12-381-polynomial
  5. octez-mec
  6. octez-polynomial
  7. octez-smart-rollup-wasm-benchmark-lib
  8. SourceCode_ASCII
  9. tezos-baking-016-PtMumbai >= "17.1"
  10. tezos-baking-017-PtNairob
  11. tezos-baking-alpha >= "17.1"
  12. tezos-base >= "17.1"
  13. tezos-clic >= "17.1"
  14. tezos-client-016-PtMumbai >= "17.1"
  15. tezos-client-017-PtNairob
  16. tezos-client-alpha >= "17.1"
  17. tezos-client-base >= "17.1"
  18. tezos-client-base-unix >= "17.1"
  19. tezos-context >= "17.1"
  20. tezos-crypto >= "17.1"
  21. tezos-crypto-dal >= "17.1"
  22. tezos-error-monad >= "17.1"
  23. tezos-hacl >= "17.1"
  24. tezos-layer2-store >= "17.1"
  25. tezos-lwt-result-stdlib >= "17.1"
  26. tezos-mockup >= "17.1"
  27. tezos-p2p >= "17.1"
  28. tezos-protocol-environment >= "17.1"
  29. tezos-proxy >= "17.1"
  30. tezos-proxy-server-config >= "17.1" & < "18.0"
  31. tezos-requester >= "17.1"
  32. tezos-rpc-http-server >= "17.1"
  33. tezos-sapling >= "17.1"
  34. tezos-scoru-wasm-helpers < "17.1"
  35. tezos-shell >= "17.1"
  36. tezos-shell-services >= "17.1"
  37. tezos-signer-backends >= "17.1"
  38. tezos-stdlib >= "17.1"
  39. tezos-stdlib-unix >= "17.1"
  40. tezos-store >= "17.1"
  41. tezos-version >= "17.1"
  42. tezos-webassembly-interpreter >= "17.1"
  43. tezos-workers >= "17.1"
  44. tezt-performance-regression
  45. tezt-tezos < "18.0"
  46. universo

Conflicts (2)

  1. js_of_ocaml-lwt < "4.0.0"
  2. js_of_ocaml < "4.0.0"