akshattandon / projectlombok

Automatically exported from code.google.com/p/projectlombok
0 stars 0 forks source link

Sonar/Jacoco shows @EqualsAndHashCode as untested #589

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Make a class with a number of fields and @EqualsAndHashCode or @Data 
annotations
2. Test it through Jacoco but don't call the equals and/or hashcode methods
3. Upload the test results to Sonar

What is the expected output? What do you see instead?
I expected Jacoco to not care about the generated methods and show the line 
with the annotation as having no code to test. Certainly this was the case in 
Lombok 0.12.0, where the line with the annotation would show up as green. Since 
1.12.2 it shows up as untested branches (see attachments), I'm guessing from 
the equals method.

Using Lombok we could test actual functionality instead of the boilerplate code 
and get the test coverage to 95% and up. With the untested equals methods this 
dropped to about 50%. 

What version of the product are you using? On what operating system?
Lombok 1.12.2, Java 7.

Please provide any additional information below.
Using Jacoco 0.6.3.201306030806, with TestNG 6.8.7 on SonarQube 3.7.1

Original issue reported on code.google.com by piderman@gmail.com on 11 Oct 2013 at 11:37

Attachments:

GoogleCodeExporter commented 9 years ago
Issue confirmed.

I've the same enviroment (Lombok 1.12.2 + Java 7 + Jacoco + TestNG + SonarQube).

Original comment by pang...@gmail.com on 16 Oct 2013 at 4:32

GoogleCodeExporter commented 9 years ago
Can you tell me what change triggered this result? I mean, what code do we now 
generate differently?

Original comment by r.spilker on 20 Nov 2013 at 1:44

GoogleCodeExporter commented 9 years ago
Still happens with 1.12.4 (after upgrading from 0.12.0).

Using Java 7, Jacoco, JUnit, SonarQube.

Original comment by and.svan...@gmail.com on 28 Feb 2014 at 9:24

GoogleCodeExporter commented 9 years ago
The issue is still there after so long... if there is an accepted solution I 
can help implement it. Would a marking annotation work?

Original comment by rlogia...@gmail.com on 12 Jun 2014 at 3:49

GoogleCodeExporter commented 9 years ago
This not a lombok issue. 
The generated code needs to be covered by the UTs or ITs as it had been 
manually written.
Lombok cannot fix that even it combined amount of branches in the generated 
code is high.

Original comment by fabrice....@gmail.com on 18 Jul 2014 at 10:48

GoogleCodeExporter commented 9 years ago
@fabrice:

In that case we would've to test each and every branch of the generated code, 
which can be very high (more than 200 in on of the case)
Can't there be a way by which lombok can mark them and Jacoco understands not 
to include marked for code coverage.

Original comment by pops7...@gmail.com on 10 Feb 2015 at 9:53

GoogleCodeExporter commented 9 years ago
Would it be possible to generate a boilerplate test for boilerplate code? 
Perhaps add a new annotation like:
@EqualsAndHashCodeTest
that would generate a Junit test for the annotated private member? See 
https://gist.github.com/rherrmann/2970842

For instance:
@EqualsAndHashCodeTest
private Point point = new Point(1,2);

Would generate:
@Test
private void boilerPlateLombokEqualsAndHashCodeTest () {
  EqualsTester<Point> equalsTester = newInstance( new Point( 1, 2 ) );
  equalsTester.assertEqual( new Point( 1, 2 ), new Point( 1, 2 ) );
  equalsTester.assertNotEqual( new Point( 1, 2 ), new Point( 3, 4 ) );
}

Original comment by ge...@umich.edu on 13 Apr 2015 at 8:51