portfolio icon indicating copy to clipboard operation
portfolio copied to clipboard

Test Smell: assertion with the wrong parameter order

Open TestSmell opened this issue 3 years ago • 0 comments

Hi!

Description: we detect that some assertions in your test code have the wrong parameter orders. For example, the test case named ''testExternalIdentifier()'' in ''SecurityTest.java'' wrties the ''assertEquals'' as image However, referring to the API documentation of ''org.junit.Test'', the correct API usage of ''assertEquals'' is ''assertEquals(Object expected, Object actual)''.

Negative: Once the test case fails, the ''assertEquals()'' assertion with the wrong parameter order will give the wrong log information. The log information will say:’’ java.lang.AssertionError: expected [actual value] but found [ except value]’’ This is confusing, to say the least, and you shouldn't have to deal with a possible misdirection of that message.

Solution: Generally, the excepted value should be a known value, such as a real number, a string, etc. The actual value should be the result of the method-under-test. Therefore, the parameter order of ''assertEquals'' should be exchanged.

We list the test cases with the same problem as follows: testExternalIdentifier() in SecurityTest.java testInvalidRGB() in ColorConversionTest.java testToRGB() in ColorConversionTest.java testToHSB() in ColorConversionTest.java testDividendPerShareNoShares() in DividendTransactionTest.java....

TestSmell avatar Aug 15 '22 08:08 TestSmell