Put one tested module in Mix: full examples and further reading
The original lesson material is preserved here for reference. The main notebook focuses on this lesson's core question.
Read a Mix project layout and run a focused ExUnit test.
Create score_card, run its generated tests, and add one assertion for a pure function.
Run this first
Run it once, change one input, and compare the new result.
# Run these commands in the system terminal
mix new score_card
cd score_card
mix testMix creates lib/, test/, and mix.exs; the generated test should pass.
Steps for the full example
- Read
mix new: Create a standard project tree. - Read
mix test: Compile the project and run ExUnit tests. - Read
assert left == right: Fail the test when both sides differ.
Original lesson notes
Run the example first. Predict one result, then change one input and run it again.
ExUnit discovers files ending in _test.exs under the test directory.
assert states a result that must be true.
Symbols and terms
mix new- Create a standard project tree.
mix test- Compile the project and run ExUnit tests.
assert left == right- Fail the test when both sides differ.
- test file
- ExUnit discovers files ending in
_test.exsunder thetestdirectory. - assertion
assertstates a result that must be true.- dependency
- Dependencies are declared in
mix.exsand fetched with Mix.
Original full exercise
Write a test that expects ScoreCard.pass?(70) to be true.
test "70 passes" do
assert ScoreCard.pass?(70) == ____
endThe assertion should expect true.
Show hint
Replace the blank with the Boolean result.
Show original answer
test "70 passes" do
assert ScoreCard.pass?(70) == true
endWhere do normal source modules live?
Mix projects keep application source under lib/.
Original lesson takeaways
- Mix gives a project a shared layout.
- Tests describe observable behavior.
- Keep early tests focused on pure functions.