code coverage in practice - eclipsecon france2018 · 2017-06-22 · white-box testing (unit tests)...
TRANSCRIPT
![Page 1: Code Coverage in Practice - EclipseCon France2018 · 2017-06-22 · White-box Testing (Unit Tests) Integration Testing Usage Analysis Differential Code Coverage JaCoCo works for any](https://reader036.vdocuments.us/reader036/viewer/2022062601/5e4274331c21e515eb4e21c0/html5/thumbnails/1.jpg)
Code Coveragein Practice
Evgeny Mandrikov, SonarSource, @_godin_
![Page 2: Code Coverage in Practice - EclipseCon France2018 · 2017-06-22 · White-box Testing (Unit Tests) Integration Testing Usage Analysis Differential Code Coverage JaCoCo works for any](https://reader036.vdocuments.us/reader036/viewer/2022062601/5e4274331c21e515eb4e21c0/html5/thumbnails/2.jpg)
Application
Tests
![Page 3: Code Coverage in Practice - EclipseCon France2018 · 2017-06-22 · White-box Testing (Unit Tests) Integration Testing Usage Analysis Differential Code Coverage JaCoCo works for any](https://reader036.vdocuments.us/reader036/viewer/2022062601/5e4274331c21e515eb4e21c0/html5/thumbnails/3.jpg)
85 6 7
2004 2005 2006 2007 2008 2009 2010 2011 2012
EMMA1.x
2013 2014 2015 2016
JaCoCo
2.x
EclEmma1.x
![Page 4: Code Coverage in Practice - EclipseCon France2018 · 2017-06-22 · White-box Testing (Unit Tests) Integration Testing Usage Analysis Differential Code Coverage JaCoCo works for any](https://reader036.vdocuments.us/reader036/viewer/2022062601/5e4274331c21e515eb4e21c0/html5/thumbnails/4.jpg)
Tested on 5 major JDK versions
![Page 5: Code Coverage in Practice - EclipseCon France2018 · 2017-06-22 · White-box Testing (Unit Tests) Integration Testing Usage Analysis Differential Code Coverage JaCoCo works for any](https://reader036.vdocuments.us/reader036/viewer/2022062601/5e4274331c21e515eb4e21c0/html5/thumbnails/5.jpg)
We do not only identify issues in JaCoCo...
![Page 6: Code Coverage in Practice - EclipseCon France2018 · 2017-06-22 · White-box Testing (Unit Tests) Integration Testing Usage Analysis Differential Code Coverage JaCoCo works for any](https://reader036.vdocuments.us/reader036/viewer/2022062601/5e4274331c21e515eb4e21c0/html5/thumbnails/6.jpg)
JaCoCoValidationTest Suite
![Page 7: Code Coverage in Practice - EclipseCon France2018 · 2017-06-22 · White-box Testing (Unit Tests) Integration Testing Usage Analysis Differential Code Coverage JaCoCo works for any](https://reader036.vdocuments.us/reader036/viewer/2022062601/5e4274331c21e515eb4e21c0/html5/thumbnails/7.jpg)
85 6 7
2004 2005 2006 2007 2008 2009 2010 2011 2012
EMMA1.x
2013 2014 2016 2017
JaCoCo
2.x
EclEmma1.x
3.x
9
![Page 8: Code Coverage in Practice - EclipseCon France2018 · 2017-06-22 · White-box Testing (Unit Tests) Integration Testing Usage Analysis Differential Code Coverage JaCoCo works for any](https://reader036.vdocuments.us/reader036/viewer/2022062601/5e4274331c21e515eb4e21c0/html5/thumbnails/8.jpg)
EclEmma @ Eclipse● Proposal accepted in July 2016
(https://projects.eclipse.org/projects/technology.eclemma)● Initial contribution and IP clearance (https://github.com/eclipse/eclemma)● 3.0.0 is part of Oxygen (Eclipse IDE for Java developers, …)
○ almost identical functionality as 2.3.3 with new namespace org.eclipse.eclemma.*○ updatable from 2.3.3○ Look&Feel adjustments for better integration○ HiDPI icons○ still works for Eclipse 3.8 and greater○ Java 9 ready
![Page 9: Code Coverage in Practice - EclipseCon France2018 · 2017-06-22 · White-box Testing (Unit Tests) Integration Testing Usage Analysis Differential Code Coverage JaCoCo works for any](https://reader036.vdocuments.us/reader036/viewer/2022062601/5e4274331c21e515eb4e21c0/html5/thumbnails/9.jpg)
What can code coverage be used for? ● White-box Testing (Unit Tests)● Integration Testing● Usage Analysis● Differential Code Coverage
● JaCoCo works for any code running on the JVM● It is not intended to be used for profiling!
![Page 10: Code Coverage in Practice - EclipseCon France2018 · 2017-06-22 · White-box Testing (Unit Tests) Integration Testing Usage Analysis Differential Code Coverage JaCoCo works for any](https://reader036.vdocuments.us/reader036/viewer/2022062601/5e4274331c21e515eb4e21c0/html5/thumbnails/10.jpg)
Integration with Various Tools● IDE
○ Eclipse EclEmma™○ IntelliJ IDEA○ NetBeans
● Build○ Maven○ Gradle○ Ant
● CI○ Jenkins○ TeamCity○ Visual Studio Team Services○ SonarQube
● you name it - Java API
![Page 11: Code Coverage in Practice - EclipseCon France2018 · 2017-06-22 · White-box Testing (Unit Tests) Integration Testing Usage Analysis Differential Code Coverage JaCoCo works for any](https://reader036.vdocuments.us/reader036/viewer/2022062601/5e4274331c21e515eb4e21c0/html5/thumbnails/11.jpg)
Demo● Unit Testing within Eclipse IDE● Differential Code Coverage
within Eclipse IDE
![Page 12: Code Coverage in Practice - EclipseCon France2018 · 2017-06-22 · White-box Testing (Unit Tests) Integration Testing Usage Analysis Differential Code Coverage JaCoCo works for any](https://reader036.vdocuments.us/reader036/viewer/2022062601/5e4274331c21e515eb4e21c0/html5/thumbnails/12.jpg)
Principles and Best Practices● Don’t care about percentage value, observe the amount of untested code● Focus on coverage of modified and new code● Make coverage analysis an inherent part of your build/test chain● Make coverage reports available to everybody in the team
○ But not the management!
● Always go for functional coverage when writing tests○ Just executing code will not improve its quality!
![Page 13: Code Coverage in Practice - EclipseCon France2018 · 2017-06-22 · White-box Testing (Unit Tests) Integration Testing Usage Analysis Differential Code Coverage JaCoCo works for any](https://reader036.vdocuments.us/reader036/viewer/2022062601/5e4274331c21e515eb4e21c0/html5/thumbnails/13.jpg)
Continuous Inspection - SonarQube
![Page 14: Code Coverage in Practice - EclipseCon France2018 · 2017-06-22 · White-box Testing (Unit Tests) Integration Testing Usage Analysis Differential Code Coverage JaCoCo works for any](https://reader036.vdocuments.us/reader036/viewer/2022062601/5e4274331c21e515eb4e21c0/html5/thumbnails/14.jpg)
JaCoCo works on Java class files only
*.class
On-the-fly or Pre-instrumentation
Analysis
*.exec
Runtime
![Page 15: Code Coverage in Practice - EclipseCon France2018 · 2017-06-22 · White-box Testing (Unit Tests) Integration Testing Usage Analysis Differential Code Coverage JaCoCo works for any](https://reader036.vdocuments.us/reader036/viewer/2022062601/5e4274331c21e515eb4e21c0/html5/thumbnails/15.jpg)
Common Pitfalls and how to avoid them● Different Class Files runtime/analysis
○ different compiler implementations○ different compiler versions○ different compiler settings○ Pack200
● Different version of the same class in same group● Not graceful JVM termination● Reflection (synthetic fields and methods)● Pre-instrumentation requires direct dependency on the JaCoCo runtime● Interoperability with other agents
○ PowerMock might bypass agents, because reads files○ overrides JaCoCo init method
![Page 16: Code Coverage in Practice - EclipseCon France2018 · 2017-06-22 · White-box Testing (Unit Tests) Integration Testing Usage Analysis Differential Code Coverage JaCoCo works for any](https://reader036.vdocuments.us/reader036/viewer/2022062601/5e4274331c21e515eb4e21c0/html5/thumbnails/16.jpg)
Get Involved● EclEmma and JaCoCo user's group:
○ [email protected]○ https://groups.google.com/forum/#!forum/jacoco
● EclEmma○ http://www.eclemma.org/○ https://github.com/eclipse/eclemma
● JaCoCo○ http://www.jacoco.org/jacoco/index.html
○ https://github.com/jacoco/jacoco
![Page 17: Code Coverage in Practice - EclipseCon France2018 · 2017-06-22 · White-box Testing (Unit Tests) Integration Testing Usage Analysis Differential Code Coverage JaCoCo works for any](https://reader036.vdocuments.us/reader036/viewer/2022062601/5e4274331c21e515eb4e21c0/html5/thumbnails/17.jpg)
Evaluate the Sessions
-1 0 +1Sign in and vote at eclipsecon.org