Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test smell: the wrong parameter order in ''assertEquals'' assertion #1101

Open
TestSmell opened this issue Aug 15, 2022 · 1 comment · May be fixed by #1102
Open

Test smell: the wrong parameter order in ''assertEquals'' assertion #1101

TestSmell opened this issue Aug 15, 2022 · 1 comment · May be fixed by #1102

Comments

@TestSmell
Copy link

Hi!

Description:
we detect that some assertions in your test code have the wrong parameter orders.
For example, the test case named ''testToByteArrayConvertsInt()'' in ''IdentifierTest.java'' writes the ''assertEquals'' assertion as
image
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:

  1. testToByteArrayConvertsHex() in IdentifierTest.java
  2. testToByteArrayConvertsInt() in IdentifierTest.java
  3. testToByteArrayConvertsUuids() in IdentifierTest.java
  4. testCalculateAccuracyWithRssiEqualsPowerOnInternalProperties() in BeaconTest.java
  5. stopRangingBeaconsInRegionTest() in BeaconManagerTest.java
  6. startRangingBeaconsInRegionMultipleInvocationsTest() in BeaconManagerTest.java
  7. testRecognizeBeacon() in AltBeaconTest.java ....
@davidgyoung
Copy link
Member

Contributions to this library are welcome! Please feel free to open a pull request to address these issue.

@shinwan2 shinwan2 linked a pull request Aug 28, 2022 that will close this issue
1 task
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 a pull request may close this issue.

2 participants