Bikeshed: Where Does the Expected Value Go?

| Comments

Does the expected value of a unit test assertion go on the right or the left side?

Option 1: Expected Value on Left

    assert "Aaron Oliver" == user.fullname()

Option 2: Expected Value on Right

    assert user.fullname() == "Aaron Oliver"

Yes, it’s a bikeshed issue, but I think it’s worth discussing. Mixing conventions is confusing.

I think option 2 is closer to how we speak and think about test assertions:

Verify the result is what was expected

However, I’ve been doing option 1 since my Java days, I think because that’s how JUnit wants it.

What’s the best way?

blog comments powered by Disqus