ksql icon indicating copy to clipboard operation
ksql copied to clipboard

Test Smell: Wrong 'AssertEquals' Usages

Open TestSmell opened this issue 3 years ago • 0 comments
trafficstars

Hi! We detect several wrong assertion API usages in your project.

description: Referring to the API document of ''org.junit.Test'' , the correct API of ''AssertEquals'' is ''assertEquals(Object expected, Object actual)''. However, your test cases write the ''AssertEqualst'' assertion with a wrong parameter order. For example, the test case named ''filter_shouldIncludeBelowThreshold()'' writes the assertion as ''assertEquals(host.getReasonNotSelected(), "");''.

Negatives: 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: Actually, the expected value should be '''' in your test case and the actual value should be the function invoke (i.e., host.getReasonNotSelected()), and thus the correct ''assertEquals'' assertion should be changed into ''assertEquals("", host.getReasonNotSelected());''.

Test cases in your project: filter_shouldIncludeBelowThreshold() in MaximumLagFilterTest.java shouldCreateCommandForAlterTable() in AlterSourceFactoryTest.java shouldCreateCommandForAlterStream() in AlterSourceFactoryTest.java shouldDetectTheCorrectLeakedTopics() in TransientQueryCleanupServiceTest.java shouldCreateExecutionPlanForInsert() in ExecutionPlanBuilderTest.java shouldReturnSubstringCapturedByGroupNumber() in RegexpExtractTest.java shouldReturnSubstringWhenMatched() in RegexpExtractTest.java

TestSmell avatar Aug 15 '22 03:08 TestSmell