We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
Generating multiple test cases from a single test in Elixir using a for-comprehension!
amos-kibet
Created
🧪 TIL: You can generate multiple test cases from a single test in Elixir using a for-comprehension! Super clean way to test similar scenarios.
for status <- [:active, :archived, :close, :delete, :draft, :planned, :public] do
@tag status: status
test "filters courses by status: #{status}", %{status: status} do
%MyApp.Course{id: course_id} = course_fixture(%{status: status})
assert {:ok, [course_from_db]} = MyApp.Course.list_courses(status)
assert course_from_db.id == course_id
end
end
7 tests, 1 block of code! 🎯
Credits to Jeff Sandberg. Read more here.
Copy link
copied to clipboard