Skip to content

Invoke JUnit assertEquals with Argument Order (expected, actual) - #242

Merged
stkent merged 1 commit into
exercism:masterfrom
nigelhp:assert-arg-order
Jan 9, 2017
Merged

stkent merged 1 commit into
exercism:masterfrom
nigelhp:assert-arg-order

Conversation

@nigelhp

@nigelhp nigelhp commented Jan 9, 2017

Copy link
Copy Markdown

The JUnit API documents assertEquals as taking the expected argument
before the actual argument. Failure to adhere to this can result in
very confusing test failure messages.

For example in testTransformOneValue 'old' contains 'A' and 'expected'
contains 'a'. If the implementer does not lower-case the key, the
failure message is as follows if the argument order is
(actual, expected):

EtlTest > testTransformOneValue FAILED
java.lang.AssertionError: expected:<{A=1}> but was:<{a=1}>
at org.junit.Assert.fail(Assert.java:88)
at org.junit.Assert.failNotEquals(Assert.java:834)
at org.junit.Assert.assertEquals(Assert.java:118)
at org.junit.Assert.assertEquals(Assert.java:144)
at EtlTest.testTransformOneValue(EtlTest.java:27)

This is very confusing as "was:<{a=1}>" is exactly what we were hoping
the result would be.

The JUnit API documents assertEquals as taking the expected argument
before the actual argument.  Failure to adhere to this can result in
very confusing test failure messages.

For example in testTransformOneValue 'old' contains 'A' and 'expected'
contains 'a'.  If the implementer does not lower-case the key, the
failure message is as follows if the argument order is
(actual, expected):

EtlTest > testTransformOneValue FAILED
    java.lang.AssertionError: expected:<{A=1}> but was:<{a=1}>
        at org.junit.Assert.fail(Assert.java:88)
        at org.junit.Assert.failNotEquals(Assert.java:834)
        at org.junit.Assert.assertEquals(Assert.java:118)
        at org.junit.Assert.assertEquals(Assert.java:144)
        at EtlTest.testTransformOneValue(EtlTest.java:27)

This is very confusing as "was:<{a=1}>" is exactly what we were hoping
the result would be.
@stkent

stkent commented Jan 9, 2017

Copy link
Copy Markdown
Contributor

Good catch; thanks! Let's get this merged on CI success :)

@stkent
stkent merged commit 85ea3d4 into exercism:master Jan 9, 2017
@nigelhp
nigelhp deleted the assert-arg-order branch January 10, 2017 22:08
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

Successfully merging this pull request may close these issues.

2 participants