[erlang-questions] Eunit fixtures - can someone show an example?

Richard Carlsson <>
Fri Mar 27 20:52:42 CET 2009

ryeguy wrote:
> Can someone show me an example of a test fixture with a setup and
> teardown function? The docs are sparse in this area, and don't have
> any examples of it. I can't figure it out.

If the tests need some data from the setup function in order to run,
you can write like this (with an "instantiator" for the body of tests):

my_test_() ->
    fun () -> file:open(...) end,
    fun (FD) -> file:close(FD) end,
    fun (FD) ->

or if the tests don't need that data (FD above and P below),
you can list them directly without an instantiator:

my_test_() ->
    fun () -> P = spawn(...), register(foo, P), P end,
    fun (P) -> exit(P, kill) end,
    [?_test(...foo ! hello...),
     ?_test(...foo ! bonjour...),
     ?_test(...foo ! hola...)]


More information about the erlang-questions mailing list