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: Assertion with the wrong parameter order #262

Open
TestSmell opened this issue Aug 15, 2022 · 0 comments
Open

Test Smell: Assertion with the wrong parameter order #262

TestSmell opened this issue Aug 15, 2022 · 0 comments

Comments

@TestSmell
Copy link

Hi!

description:
Referring to the API document of ''org.junit.Test'' , the correct API of ''AssertEquals'' is ''assertEquals(Object expected, Object actual)''.
However, we detect that some assertions in your test code have the wrong parameter orders.
For example, the test case named ''testAddressFunctions()'' in ''TestAddress.java'' writes the assertion into ''Assert.assertEquals( address.getOriginal(), a);'', ''Assert.assertEquals( address.getUrl().getHost(), "www.httprecipes.com");'', ''Assert.assertEquals( address2.getOriginal(), a);'', and ''Assert.assertEquals( address3.getOriginal(), a);''.

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: "expected [false] but found [true]", where it should have said "expected [true] but found [false]". 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 -f the-method-under-test.
Therefore, the ''Assert.assertEquals( address.getOriginal(), a);'' should be changed into ''Assert.assertEquals(a, address.getOriginal());'';
the ''Assert.assertEquals( address.getUrl().getHost(), "www.httprecipes.com");'' should be changed into ''Assert.assertEquals("www.httprecipes.com", address.getUrl().getHost());''; ....

We list the test cases with the same problem as follows:
''testAddressFunctions()'' in TestAddress.java
''testClone()'' in TestBiPolarNeuralData.java
''testAStar()'' in TestSearch.java
''testBredthFirstSearch()'' in TestSearch.java
''testDepthFirstSearch()'' in TestSearch.java
''check2D()'' in TestNormArray.java
''check1D()'' in TestNormArray.java
''check()'' in TestMapped.java ...

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

No branches or pull requests

1 participant