errors icon indicating copy to clipboard operation
errors copied to clipboard

在测试用例中该如何比较

Open archer-wyz opened this issue 1 year ago • 0 comments

我有一个函数:

func Create () error{
  return errors.WithCode(errcode.Create, "创建错误")
}

测试中一般这样写:

testCases := []struct {
		name    string
		wantErr error
	}{
               name: "xxx",
               wantErr: errors.WithCode(errcode.Create, "创建错误")
        }
}

for _, tc := range testCases {
    t.Run(tc.name, func(t *testing.T)) {
        err := Create()
        assert.Equal(t, tc.wantErr, err)
    }
}

类似上面的并不会比较成功,现在只能人眼打印去看具体的信息,有什么优雅的方法吗?

archer-wyz avatar May 30 '23 09:05 archer-wyz