Minimalist BDD for Erlang, sans cucumbers
It's pronounced "better".
- To enforce strictness as to what is being tested
- To allow groups of develpers to understand each other's test cases
- To eliminate
init_per_*
andend_per_*
anti-patterns
Here is a basic test with independent givens:
bddr:test([given_app_started(),
given_user_in_db("user", "password")],
fun([App,{User,Pass}]) ->
when_user_logs_in(App, User, Pass) end,
fun(Screen) ->
"Welcome, User!" = welcome_text(Screen) end).
If that seems too raw to you, add some sugar in the form of macros:
-include_lib("bddr/include/bddr.hrl").
bddr:test(?Given() ->
server_running() end,
?When(Server) ->
i_query_server(Server, "hello") end,
?Then(Reply) ->
{ok, "hello to you too!"} = Reply end,
?Teardown(Server) ->
stop_server(Server) end)
Using bddr_suite:run_suite/1
. Your test suite must export a common-test-like
all/0
listing of test names.
test: compile
@erl -shutdown_time 1 -noshell -pa deps/ebin -pa ebin -pa test \
-eval 'bddr_suite:run_suite(my_test_SUITE).'
No, the implementation is intentionally minimal. It's the developer's responsibility to provide his/her abstractions for the tested components. Remember, your tests are just Erlang code. Make it readable and extensible for others. Be humane.
Additional copyrights
The test suite contains dynamic_compile.erl
, copyright 2007 by Mats Cronqvist,
Chris Newcombe, and Jacob Vorreuter, licensed under the MIT License.