EUnit examples: a simple test

31 Mar 2023 08:10 erlang eunit

A simple EUnit test might look like this:

% in test/meaning_test.erl

the_test() ->
    ?assertEqual(42, meaning:meaning_of([life, universe, everything])).

Of note:

  • The module is in the test/ directory.
  • It’s named with _test.erl.
  • It includes (using include_lib) the eunit.hrl include file.
  • Our test is named with _test.

The test can be run with rebar3 eunit or – if you’re using – make eunit. If you’re using mix to build your Erlang project, then check out my mix_eunit project.