I'm using ExUnit for testing my Elixir app, which is a card game.
I find that with every test I write, I start by creating a fresh deck of cards.
test "Do This Crazy Thing do
deck = Deck.create()
[...]
end
test "Do This Other Crazy Unrelated Thing" do
deck = Deck.create()
[...]
end
Is there a way to factor this out so that a new deck can just be created before every test case? I know there's something close to this with setup do [...] end
, but I don't think that's the solution for me.
Do I need a different test framework? Do I need to use setup
in some way I haven't thought of yet?
-Augie
You can use def setup
with the meta
has just for this.
Example:
defmodule DeckTest do
use ExUnit.Case
setup do
{:ok, cards: [:ace, :king, :queen] }
end
test "the truth", meta do
assert meta[:cards] == [:ace, :king, :queen]
end
end
Here's some more info
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With