Skip to content

Latest commit

 

History

History
61 lines (50 loc) · 1.1 KB

02-05-test-elixir.md

File metadata and controls

61 lines (50 loc) · 1.1 KB

%{ title: "Tests in Elixir", author: "Luiz Cattani", tags: ~w(tests elixir), description: "Testing in Elixir" }

Elixir Test

ExUnit

Tool default in Elixir language to test our code

Elixir supports the ability to run tests concurrently within the same Elixir instance.

Running

Run all specs

$ mix test

Run a specific spec

$ mix test test/hello_world_test.exs

Tags

We can create tags for our specs

@tag :simple_test
test "does not greets the world" do
  assert HelloWorld.hello() == :world
end

only

Run the specs with a specific tag

$ mix test --only tag_name

exclude

Run all tests excluding a specific tag

$ mix test --exclude tag_name

Curiosity:

if a duplicated describe of a spec exists in the same file Elixir raise an error, awesome \o/

test "does not greets the world" do
  refute HelloWorld.hello() == :wolrd
end

test "does not greets the world" do
  assert HelloWorld.hello() == :world
end

$ mix test
(ExUnit.DuplicateTestError) "test does not greets the world" is already defined in HelloWorldTest