Mix projects
| mix new | |
| mix test | |
| mix run | |
| lib test config |
mix new
Mix is the build tool of Elixir. One command scaffolds a project with folders and files already in place.
mix new hello
The command creates lib/hello.ex for code, test/ for tests, and mix.exs for project settings. Open the generated files and read them once before changing anything.
mix test
Every generated project ships with one sample test. Run the suite early so a green baseline is familiar before real code lands.
mix test
A passing run prints a dot per test plus a summary line. A failing run prints the test name, the assertion, and the line number to open.
defmodule HelloTest do
use ExUnit.Case
test "greets" do
assert Hello.hello() == "world"
end
end
mix run
The run task boots the project and executes it. Use it to start the application once the code compiles and the tests pass.
mix run
The task also accepts an expression flag for quick checks. Prefer a real script or test for anything worth keeping, and keep one-off checks in the terminal.
Hello.hello()
IO.puts("hi")
lib test config
Three folders carry the whole project. lib/ holds application code, test/ holds ExUnit files, and config/ holds settings per environment. Small projects stay readable for a long time with exactly this split.
defmodule Hello do
def hello do
"world"
end
end
Next: Dependencies
Article author: Arthur Isaev