swagger-core icon indicating copy to clipboard operation
swagger-core 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 ''getParameterAnnotationsTest()'' in ''ReflectionUtilsTest.java'' writes the assertion as 截屏2022-08-15 下午2 47 19 However, referring to the API documentation of ''assertEquals'' is ''assertEquals(Object actual, Object excepted)''.

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 "actual [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 of the method-under-test. Therefore, the parameter order of assertions in the ''getParameterAnnotationsTest()'' test case should be changed.

We list the test cases with the same problem as follows: getParameterAnnotationsTest() in ReflectionUtilsTest.java getParameterAnnotationsForOverriddenAnnotationTest() in ReflectionUtilsTest.java testObjectProperty() in JsonDeserializationTest.java deserializePetstore3_1() in OpenAPI3_1DeserializationTest.java deserializePetstore3_1More in OpenAPI3_1DeserializationTest.java deserializePetstore3_0() in OpenAPI3_1DeserializationTest.java deserializeChangelog3_1() in OpenAPI3_1DeserializationTest.java testDeserializationOnOAS31() in OpenAPI3_1DeserializationTest.java testRefDeserializationOnOAS31() in OpenAPI3_1DeserializationTest.java assertVendorExtensions() in JsonPropertiesDeserializationTest.java testArray() in ContainerTest.java testMap() in ContainerTest.java testGetTags() in ReaderTest.java testGetServers() in ReaderTest.java ......

TestSmell avatar Aug 15 '22 06:08 TestSmell