-
Notifications
You must be signed in to change notification settings - Fork 0
Section 3 Lesson 30: Test Cases
Thiago Salles edited this page Jul 2, 2021
·
1 revision
Here's an example on how to create test cases.
I like to organize function into a describe
and put all its test cases inside of it:
describe "create_deck/1" do
test "makes 20 cards" do
deck = Cards.create_deck()
assert length(deck) == 20
end
end
describe "deal/2" do
test "works if deck has enough cards" do
deck = Cards.create_deck()
hand_size = 5
assert {:ok, hand, rest_of_deck} = Cards.deal(deck, hand_size)
assert length(hand) == hand_size
assert length(rest_of_deck) == length(deck) - hand_size
end
test "fails if deck has not enough cards" do
deck = Cards.create_deck()
assert {:error, _reason} = Cards.deal(deck, 500)
end
end
More to read:
Section 1: An Elixir Warmup
5 - Generating a Project
6 - Modules and Methods
7 - Lists and Strings
8 - Method Arguments
11 - Immutability
13 - Comprehensions Over Lists
Section 2: Pattern Matching
17 - Overview
18 - Relationship with Erlang
23 - The Pipe Operator
24 - Installing Dependencies
Section 3: Testing and Documentation
Section 4: A Few Side Topics