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
Proposal: Must-like utility #1590
Comments
So this is like the well known generic Would You only show usage in test setup, which is not the primary purpose of test assertions. How does this look in a test assertion? actual := require.Must(t, codeundertest.GetData(arg))
require.Equal(t, expected, actual) Sure, maybe, but do we also need Must2, Must3 etc.. Because type parameters cannot be variadic. It looks like Go is not going to add Must to the standard library: golang/go#32219 In my view this turns 3 lines into 2 for test assertions, 2 lines into 1 for test setup. At best it doesn't make the test more readable. I don't think we should include this. |
Rethinking it, I agree that it doesn't look to suit this project enough.
Your example looks appropriate. More clear one: // setup
x := Setup()
// act
x.MethodUnderTest()
// assertion
actual := require.Must(t, x.Get())
require.Equal(t, expected, actual) Anyway probably it will mostly used for setup.
Now I agree with you. I'd thought that it it turns 10 lines into 5 lines for test setup and it makes sense. However, probably we should just write a setup function if setup needs 10 lines. |
Parking for now. If anyone feels strongly in favour of the feature then feel free to post your reasoning. |
Description
I want something like
Must
(examples: html, regexp) for test.For functions that returns value and error, it's common to make test fail if error exists. So I wonder if I can write such code shorter.
I'm sorry but I'm not sure that here is proper project to request it. Anyway I suggest my idea.
Proposed solution
AFAIK, it's not straightforward to receive a tuple of (value, error) and testing.T simultaneously.
Following approach should work. But it looks weird a bit.
Use case
See example in description.
The text was updated successfully, but these errors were encountered: