Grokking Advanced Go
Vote

0% completed

​

Test Helpers and Golden Files

The test below calls a helper three times, and one of the three calls fails. The expected value in the last call is wrong on purpose, so that a failure report appears.

// file: order.go package orders type Item struct { SKU string Quantity int Cents int64 } type Order struct { ID int64 Items []Item } func (o Order) Total() int64 { var total int64 for _, item := range o.Items { total += int64(item.Quantity) * item.Cents } return total }
// file: order_test.go package orders import "testing" func checkTotal(t *testing.T, o Order, want int64) {

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content