Skip to content

在测试用例中该如何比较 #4

Description

@archer-wyz

我有一个函数:

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)
    }
}

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions