Grokking Advanced Go
0% completed
Table Driven Tests and Subtests
An order pays 499 cents for shipping unless it is empty or its total reaches 5,000 cents. Five cases describe that rule, and there are two common ways to test them. The first way writes one test function per case.
func TestShippingEmptyOrder(t *testing.T) { got := Order{}.ShippingCents() if got != 0 { t.Errorf("ShippingCents() = %d, want 0", got) } } func TestShippingOneCheapItem(t *testing.T) { got := Order{Items: []Item{{"A-1", 1, 1250}}}.ShippingCents() if got != 499 { t.Errorf("ShippingCents() = %d, want 499", got) } }
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%