Java rule for assertEquals parameter order

26 views
Skip to first unread message

fodp...@gmail.com

unread,
Jan 8, 2017, 12:37:49 PM1/8/17
to SonarQube
Hi

When I see a failing test case from an inherited code base, sometimes the expected and the actual values are swapped in the message of the Java exception. I have created a proof of concept rule to check that the parameters of the assertEquals are specified correctly: 

What do you think about creating a similar rule to Sonar? 

Regards
Peter

PS: example stack trace
org.junit.ComparisonFailure: 
Expected :str ing
Actual   :string
at org.junit.Assert.assertEquals(Assert.java:115)
at org.junit.Assert.assertEquals(Assert.java:144)
at com.AssertTest.testAsserts(AssertTest.java:12)


G. Ann Campbell

unread,
Jan 10, 2017, 11:36:14 AM1/10/17
to SonarQube, fodp...@gmail.com
Hi Peter,

Thanks for the idea. This was already actually in our backlog:
  1. RSPEC-3415
  2. Assertion arguments should be passed in the correct order


:-)
Ann
Reply all
Reply to author
Forward
0 new messages