Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
archer-wyz opened this issue May 30, 2023 · 0 comments
Open

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

archer-wyz opened this issue May 30, 2023 · 0 comments

Comments

@archer-wyz
Copy link

我有一个函数:

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant