← Back to lesson 18: Put one tested module in Mix

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.

Original full example
# Run these commands in the system terminal
mix new score_card
cd score_card
mix test

Mix creates lib/, test/, and mix.exs; the generated test should pass.

Steps for the full example

  1. Read mix new: Create a standard project tree.
  2. Read mix test: Compile the project and run ExUnit tests.
  3. 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.exs under the test directory.
assertion
assert states a result that must be true.
dependency
Dependencies are declared in mix.exs and fetched with Mix.

Original full exercise

Write a test that expects ScoreCard.pass?(70) to be true.

Exercise starter
test "70 passes" do
  assert ScoreCard.pass?(70) == ____
end

The assertion should expect true.

Show hint

Replace the blank with the Boolean result.

Show original answer
Reference answer
test "70 passes" do
  assert ScoreCard.pass?(70) == true
end
Where do normal source modules live?

Mix projects keep application source under lib/.

Original lesson takeaways
Design trade-offs and language comparisons
Original course references