encog-java-core icon indicating copy to clipboard operation
encog-java-core copied to clipboard

Test Smell: Assertion with the wrong parameter order

Open TestSmell opened this issue 3 years ago • 1 comments

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 ...

TestSmell avatar Aug 15 '22 04:08 TestSmell

Hi @TestSmell ,
I noticed this issue was reported in 2022, and I believe it's still relevant. I can submit a PR to fix these incorrect assertEquals() parameter orders. Let me know if this would be helpful.

Looking forward to your response!
Thanks.

GitGautamHub avatar Apr 02 '25 04:04 GitGautamHub