Put one tested module in Rebar3: full examples and further reading
The original lesson material is preserved here for reference. The main notebook focuses on this lesson's core question.
Create an Erlang application and run a focused EUnit test.
Create score_card, compile it, and run one passing EUnit assertion.
Run this first
Run it once, change one input, and compare the new result.
%% src/score_card.erl
-module(score_card).
-export([pass/1]).
-include_lib("eunit/include/eunit.hrl").
pass(Score) when is_integer(Score), Score >= 60, Score =< 100 -> true;
pass(_Score) -> false.
%% EUnit discovers functions whose names end in _test
pass_test() ->
?assertEqual(true, pass(70)).After rebar3 new app score_card, save the module and run rebar3 eunit; the focused test passes.
Steps for the full example
- Read
rebar3 new app: Create an OTP application project. - Read
rebar3 compile: Compile project modules. - Read
rebar3 eunit: Run EUnit tests.
Original lesson notes
Run the example first. Predict one result, then change one input and run it again.
Rebar3 creates Erlang projects, resolves dependencies, compiles code, and runs tests.
EUnit discovers small test functions and assertion macros.
Symbols and terms
rebar3 new app- Create an OTP application project.
rebar3 compile- Compile project modules.
rebar3 eunit- Run EUnit tests.
- Rebar3
- Rebar3 creates Erlang projects, resolves dependencies, compiles code, and runs tests.
- EUnit
- EUnit discovers small test functions and assertion macros.
- profile
- Rebar3 profiles keep test or development dependencies out of production builds.
Original full exercise
Write an EUnit assertion that 70 passes.
pass_test() ->
?assertEqual(____, score_card:pass(70)).Expect true.
Show hint
EUnit macros come from eunit.hrl.
Show original answer
pass_test() ->
?assertEqual(true, score_card:pass(70)).Should generated _build/ files be committed?
No. Rebar3 regenerates build output from source and configuration.
Original lesson takeaways
- Use Rebar3 for repeatable projects.
- Keep source under
src/. - Run EUnit from the project root.