Eunit Terminology
Based mostly on https://github.com/richcarl/eunit/blob/master/doc/overview.edoc
Simple Test
A function ending in _test and which takes no arguments
The test will always pass unless an exception is raised e.g. 1 =:= 2
You can use assert macros to cause the function to pass or fail
From the doc:
"A drawback of simple test functions is that you must write a separate
function (with a separate name) for each test case."
However you could write a _test() function which contains a list of assert statements ??
eunit:test(someModule) will export all simple tests.
Test
A fun expression that takes no arguments
e.g.
fun () -> ?assert(1 + 1 =:= 2) end.
Test Object
An assert which starts with an underscore
"You can think of the initial underscore as signalling test object."A simple test can be converted into a test object:
?_test(assert(BoolExpr)) % this is now a test object
Test Generator
A function ending in _test_
Returns a representation of a set of tests (that is a test set).
e.g.
basic_test_() -> fun () -> ?assert(1 + 1 =:= 2) end.which is the same as
basic_test_() -> ?_assert(1 + 1 =:= 2).'''Test generators cannot return simple tests ?
eunit:test(someModule) will export all test generators.
Simple Test Object (2nd definition)
A nullary functional value (i.e., a fun that takes zero arguments).
e.g.
fun () -> ... end
Test Set
A list of test objects or a list of other test sets.
Instantiator
Used inside a fixture, takes some state and returns a test set
It behaves like a generator
Is defined by:
((R::any()) -> Tests)
It can be used in a setup fixture like this:
{setup, Setup, Cleanup, Tests | Instantiator}
or used in a foreach fixture like
{foreach, Setup, Cleanup, [Tests | Instantiator]}
Fixture
Sets up state for a test set and takes down the state at the end of the test set
By default a separate process is responsible for the setup and teardown and another process is used for the test. Therefore if the test causes a crash, the cleanup will always be done.
A setup fixture works differently to a foreach fixture.
A setup fixture sets up state, runs all test cases and then does a cleanup.
A foreach fixture will setup state for each test case and teardown after each test case.
e.g.
higher_order_test_() ->{"Higher Order Tests",[{"Setup Test",{setup,fun () -> 4711 end,fun (4711) -> ok end,fun (X) ->[{"1st", ?_assert(X =:= 4711)},{"2nd", ?_assert(X =:= 4711)},{"3rd", ?_assert(X =:= 4711)}]end}},{"Foreach Test",{foreach,fun () -> 4711 end,fun (4711) -> ok end,[fun (R) -> {"1st", ?_assert(R =:= 4711)} end,fun (R) -> {"2nd", ?_assert(R =:= 4711)} end,fun (R) -> {"3rd", ?_assert(R =:= 4711)} end]}}.