erlang.mk: running multiple eunit tests
If you’re using erlang.mk
, you can run a single unit test suite with make eunit t=whatever
. That’s no good if you
want to run multiple test suites. Here’s a nasty hack that makes it possible.
If you’re using erlang.mk
, you can run a single unit test suite with make eunit t=whatever
. That’s no good if you
want to run multiple test suites. Here’s a nasty hack that makes it possible.
In several of the previous posts, for example Using ‘setup’, I’ve
started a server in suite_setup/0
and needed to kill it in suite_cleanup/1
. I showed a simple way to do that, but
it’s not the best. Here’s a better way to do it.
Similar to passing the result from {setup, Setup, ...
to each test, you can also pass the result from {foreach,
Setup, ...
to each test, but there are some differences.
The result from setup
is passed to cleanup
already. What if we want to pass it to each of our tests? It’s a bit
awkward, but it looks like the following:
If you want to run some setup before (and cleanup after) a list of tests, and also some setup and cleanup for each
test, you can nest setup
and foreach
:
We saw that setup
runs setup/cleanup before all tests in a list. If you want to run some setup/cleanup before each
test in a list, you can use foreach
:
What if we want to run some setup before a set of tests (and cleanup afterwards)?
While you could specify each test with a single function, you can also use a test “instantiator” (or generator) and have it return a list.
A simple EUnit test might look like this:
Some examples of how to use Erlang’s unit-testing framework, EUnit. Starting with simple examples and getting more advanced.
For when you want to run both per-suite and per-test setup and cleanup in eunit tests.
You’ve got an Erlang module with a private (not-exported) function, and you want to add some unit tests for that function? How should you do that?