【发布时间】:2019-09-10 19:36:53
【问题描述】:
我在下面有以下代码和代码测试,由于某种原因,deepEqual 返回 false 并且测试失败。现在通过阅读有关此的文档,我希望这会以真正的方式通过如此简单的事情?任何点将不胜感激。谢谢
// customer.go
type Customer struct {
customerID int
domains []string
names []string
}
func NewCustomer(customerID int, domains []string, names []string) *Customer{
return &Customer{
customerID: customerID,
domains: domains,
names:names,
}
}
// customer_test.go
func TestNewCustomer(t *testing.T) {
expected := &Customer{123,
[]string{},
[]string{},
}
got := NewCustomer(123, []string{}, []string{})
if got.customerID != expected.customerID {
t.Errorf("Got: %v, expected: %v", got.customerID, expected.customerID)
}
if reflect.DeepEqual(got, expected) {
t.Errorf("Got: %v, expected: %v", got, expected)
}
}
输出:
Got: &{123 [] []}, expected: &{123 [] []}
【问题讨论】: