You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Test Smell: the wrong parameter order in ''assertEquals'' assertion #1923
Description:
we detect that some assertions in your test code have the wrong parameter orders.
For example, the test case named ''copyFromContainerBinaryFile()'' in ''CopyArchiveFromContainerCmdIT.java'' writes the ''assertEquals'' assertion as
However, referring to the API documentation of ''org.junit.Assert’’ is ''assertEquals(Object expected, Object actual)''.
Negative:
Using ''assertEquals()'' with the wrong parameter order is a bad test practice.
Because 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 [ excepted value]’’, where it should have said "java.lang.AssertionError: expected [excepted value] but found [actual 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.
The best way to eliminate the test smell is to exchange the parameter in ''assertEquals'' assertions.
We list other test cases with the same problem as follows:
copyFromContainerBinaryFile() in CopyArchiveFromContainerCmdIT.java
version() in VersionCmdIT.java
configuredInstanceAuthConfig() in DockerClientImplTest.java
defaults() in DefaultDockerClientConfigTest.java
assertTarArchiveEntryIsExecutableFile() in CompressArchiveUtilTest.java
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This is probably a leftover from the times when TestNG was used for testing. TestNG's assertEquals has reversed parameter order in comparison to JUnit.
The switch to JUnit was in #909.
Activity
eddumelendez commentedon Sep 10, 2022
Hi @TestSmell ! thanks for raising the issue! are you willing to contribute and fix those?
stale commentedon Dec 21, 2022
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
albers commentedon Feb 8, 2023
This is probably a leftover from the times when TestNG was used for testing. TestNG's
assertEqualshas reversed parameter order in comparison to JUnit.The switch to JUnit was in #909.
Fix parameter order in `assertEquals` (#2066)