Skip to content

assert: order of expected and actual params #399

Closed as not planned
Closed as not planned

Description

@kostyantyn

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

Activity

  1. joonas-fi commented on Feb 26, 2017

    @joonas-fi

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

  2. mvdkleijn commented on Apr 7, 2020

    @mvdkleijn
    Contributor

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

  3. added this to the v2.0.0 milestone on Apr 7, 2020
  4. brackendawson commented on Feb 1, 2024

    @brackendawson
    Collaborator

    Duplicate of #146

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions