Elixir basics · Lesson 17 (open contents)
01 · Let the code speak02 · Meet six kinds of values03 · Put values together04 · Build a new list05 · Make the shapes match06 · Choose with case07 · Parse a number safely08 · Unpack &1 and the pipe09 · Put code in a project10 · Ask precise true-or-false questions11 · Read and update nested data12 · Count visible text and bytes13 · Let function clauses choose14 · Solve a list twice15 · Choose the smallest clear control form16 · Give domain data a shape17 · Put one tested module in Mix18 · Make success and failure predictable19 · Read and write one real file20 · Take only the data you need21 · Give different data one shared action22 · Write a callback contract23 · Write down the data contract24 · Test behavior and boundaries25 · Turn a project into a command26 · Write the project promise27 · Parse one real line28 · Keep the public API small29 · Make the promise executable30 · Package the edge and leave clues31 · Prove the project is done
ELIXIR · FOUNDATION · LESSON 1725 minutes

Put one tested module in Mix

Read a Mix project layout and run a focused ExUnit test.

01 · Start with the whole example

Run this first

Run it once, change one input, and compare the new result.

Elixir
# Run these commands in the system terminal
mix new score_card
cd score_card
mix test
Check the result first
  • Mix creates lib/, test/, and mix.exs; the generated test should pass.
02 · Take the code apart

Read from the first line down

  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.
03 · Meet the new symbols

Symbols are not secret signs

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.

04 · Ideas inside the code

Match each name to its meaning

01

test file

ExUnit discovers files ending in _test.exs under the test directory.

02

assertion

assert states a result that must be true.

03

dependency

Dependencies are declared in mix.exs and fetched with Mix.

05 · Make the idea clear

Why these forms are useful

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.

06 · Change it yourself

Close the answer and try

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

Practice starting point
test "70 passes" do
  assert ScoreCard.pass?(70) == ____
end

Target result: The assertion should expect true.

Stuck? Read one hint

Replace the blank with the Boolean result.

After you run it, see one answer
One answer
test "70 passes" do
  assert ScoreCard.pass?(70) == true
end
Think about it: Where do normal source modules live?

Mix projects keep application source under lib/.

Take with you

Remember these three lines

  1. 1

    Mix gives a project a shared layout.

  2. 2

    Tests describe observable behavior.

  3. 3

    Keep early tests focused on pure functions.

Lesson completeRun the code once, then mark this lesson as done.