[ANN] Tezt, a framework for all your tests

Tezt (pronounced /tɛzti/) is a test framework for OCaml that has been developed and used at Nomadic Labs to test Octez, an OCaml implementation of the Tezos blockchain. It has become quite mature and we feel it would benefit the OCaml community at large, so we are releasing it publicly as a standalone product.

Tezt is well-suited for unit tests, integration tests, and regression tests in particular. It was designed with a focus on user experience, with colourful logs, various ways to select the tests to run from the command-line, and more. It integrates well into CI pipelines. And it cleans up after itself, deleting temporary files and killing external processes. Unless you tell it not to, of course.

For a more in-depth tour of Tezt, see our latest blog post entry.

Tezt is available on opam:

opam install tezt

Have a look at the API documentation and the source code.

18 Likes

Thanks for this, it looks nice, will check it out!

Are you considering a ppx like ppx_expect to capture regression test inline?

We are indeed considering ppx_expect. From what I understand ppx_expect cannot directly be used in a test executable, but we may eventually try to implement something similar or find a way to make it work somehow.

1 Like

Very nice design. For the terminology ‘regression test’ used here, I’ve also seen that referred to as ‘snapshot test’ or ‘approval test’.

2 Likes

When you say “a test executable”, what do you mean? Certainly, ppx_expect (and more generally ppx_linine_test) build executables that you run to execute your tests. It’s not integrated with Dune’s test stanza, which is for sure something I’d love to see fixed in Dune.

I may have misunderstood something then, I was told it required library stanzas (but didn’t dig into it yet). I should have a deeper look :wink:

It does require a library stanza! But when you put an inline-tests declaration, then to execute the test, it builds an executable. (I mean, how else would you run a test?)

I think this is mostly a function of how the Dune integration works, then about the inline test framework itself. Anyway, I’m mostly wondering what the actual practical issue is, beyond the slightly confusing fact that you need to create a library to write tests.

Maybe the issue is that you want to mix inline tests and other kinds of tests in to the same executable? I don’t know how to do that offhand.

y

I think that the issue was that we cannot call the functions generated by ppx-expect from an executable, specifically from the executable of your choosing.

It does require a library stanza!

To use Tezt, you write a (test) or (executable) stanza. You then call Tezt mostly with dune exec, to be able to pass command-line arguments to Tezt, e.g. to select which tests to run.

I guess you can write a (library) stanza for the ppx, and then link this library in an executable, but I assume that there is a reason why the ppx requires a library, and that this approach would break?

It’d be nice to have some of the instructional content from the announcement blog post reproduced in the documentation

Currently the docs are just a list of modules and their members, doesn’t give any clue how to use it or what the entry point is.

Maybe the repo could have a README too. (the blog post would make a pretty good readme as it is)

2 Likes

Thanks for the suggestion. We have improved the API entrypoint: Tezt (tezt.Tezt) and added a readme: tezt/lib · master · Tezos / tezos · GitLab

Now that we have this, we can probably also add links from opam - tezt to this documentation.

2 Likes