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

assert: order of expected and actual params #399

Closed
kostyantyn opened this issue Feb 13, 2017 · 3 comments
Closed

assert: order of expected and actual params #399

kostyantyn opened this issue Feb 13, 2017 · 3 comments

Comments

@kostyantyn
Copy link

It's rather a question than an issue.

What is the reason that assert.* functions receive first expected value and then actual?
For instance: assert.Equal(t, 5, count) instead of assert.Equal(t, count, 5)

We can compare this example with if condition.
It's more natural to read if count == 5 than if 5 == count.

Another point to accept an actual param first is that it's easier to spot which fields get checked in a test because usually actual param is a variable but expected is a constant. For instance:

asssert.Equal(t, "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor", title)
asssert.Equal(t, "Ut enim ad minim veniam, quis nostrud exercitation ullamco", description)

vs

asssert.Equal(t, title, "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor")
asssert.Equal(t, description, "Ut enim ad minim veniam, quis nostrud exercitation ullamco")
@joonas-fi
Copy link

I totally agree, this is a dealbreaker for me. Golang ain't Java, and we don't need or want "yoda conditions".

@mvdkleijn
Copy link
Contributor

Related to #146 but I for one think this is a good point. It's a major breaking change though.

@brackendawson
Copy link
Collaborator

Duplicate of #146

@brackendawson brackendawson marked this as a duplicate of #146 Feb 1, 2024
@brackendawson brackendawson closed this as not planned Won't fix, can't repro, duplicate, stale Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants