Skip to content

Instantly share code, notes, and snippets.

@polvalente
Created January 13, 2021 22:41
Show Gist options
  • Save polvalente/80f32e728d0297f25d20751adea576b0 to your computer and use it in GitHub Desktop.
Save polvalente/80f32e728d0297f25d20751adea576b0 to your computer and use it in GitHub Desktop.
Exemplos de setup e argumentos
defmodule TesteTest do
use ExUnit.Case
setup_all do
# we want all tests to use the same admin id
admin_id = Ecto.UUID.generate()
%{x: 1, admin_id: admin_id}
end
setup_all %{x: x} do
%{x: x + 1, y: 3}
end
setup do
%{now: NaiveDateTime.utc_now(), user_id: Ecto.UUID.generate()}
end
test "my test with no args" do
assert 1 == 1
end
test "my test with args", %{x: x, y: y, now: now, user_id: user_id, admin_id: admin_id} do
assert x == 2
assert y == 3
IO.inspect({now, user_id, admin_id}, label: "{now, user_id, admin_id}")
end
describe "my describe" do
setup %{x: x, y: y} do
%{x: x + 1, y: y + 2}
end
test "my test with args", %{x: x, y: y, now: now, user_id: user_id, admin_id: admin_id} do
assert x == 3
assert y == 5
IO.inspect({now, user_id, admin_id}, label: "{now, user_id, admin_id}")
# aqui o admin id é o mesmo que o do teste na L26, mas o user_id e o now, não
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment