The Future of Code Coverage for Eclipse | © 2010 by Marc R. Hoffmann | made available under the EPL v1.0
The Future ofCode Coverage for Eclipse
Marc R. HoffmannEclipse Summit 20102010-11-03, Ludwigsburg
The Future of Code Coverage for Eclipse | © 2010 by Marc R. Hoffmann | made available under the EPL v1.0
The Future of Code Coverage for Eclipse
Outline
Code CoverageEclEmmaEMMA
JaCoCo
The Future of Code Coverage for Eclipse | © 2010 by Marc R. Hoffmann | made available under the EPL v1.0
The Future of Code Coverage for Eclipse
Code Coverage
„Legacy Code is simply code without tests.“
Michael Feathers:Working Effectively with Legacy Code
The Future of Code Coverage for Eclipse | © 2010 by Marc R. Hoffmann | made available under the EPL v1.0
The Future of Code Coverage for Eclipse
Example: JUnit with Code Coverage
The Future of Code Coverage for Eclipse | © 2010 by Marc R. Hoffmann | made available under the EPL v1.0
The Future of Code Coverage for Eclipse
EclEmma – Code Coverage for Eclipse
|
The Future of Code Coverage for Eclipse | © 2010 by Marc R. Hoffmann | made available under the EPL v1.0
The Future of Code Coverage for Eclipse
Monthy EclEmma Downloads
2,000
4,000
6,000
8,000
10,000
2007 2008 2009 2010
EclEmma EMMA
1.4
1.0
1.1
1.21.3
1.5
The Future of Code Coverage for Eclipse | © 2010 by Marc R. Hoffmann | made available under the EPL v1.0
The Future of Code Coverage for Eclipse
Current Status of EMMA
Great Tool! ☺Last Release
2.0.5312, 2005-06-13Project Activity
Latest Commit 2006-02-23
The Future of Code Coverage for Eclipse | © 2010 by Marc R. Hoffmann | made available under the EPL v1.0
The Future of Code Coverage for Eclipse
Action Required!
Making EMMA alive?Using a different Library?Starting a new Project?
The Future of Code Coverage for Eclipse | © 2010 by Marc R. Hoffmann | made available under the EPL v1.0
The Future of Code Coverage for Eclipse
Requirements for a Code Coverage Library
Be a Library!Open for Different Usage ScenariosDesigned for Integration
Regression TestsFramework IndependentScalable for Large ProjectsFast Enough for Agile Teams
The Future of Code Coverage for Eclipse | © 2010 by Marc R. Hoffmann | made available under the EPL v1.0
The Future of Code Coverage for Eclipse
The „JaCoCo“ Project
Java Code CoverageStarted Mid of 2009Beta Releases Sinces End of 2009EPLHosted within EclEmma (SourceForge)
www.eclemma.org/jacoco
Active TeamMarc R. Hoffmann (GER)Brock Janiczak (AUS)
The Future of Code Coverage for Eclipse | © 2010 by Marc R. Hoffmann | made available under the EPL v1.0
The Future of Code Coverage for Eclipse
JaCoCo Demo
The Future of Code Coverage for Eclipse | © 2010 by Marc R. Hoffmann | made available under the EPL v1.0
The Future of Code Coverage for Eclipse
Coverage
Analysis
Coverage Analysis
*.exec
*.class
Actual
Target
The Future of Code Coverage for Eclipse | © 2010 by Marc R. Hoffmann | made available under the EPL v1.0
The Future of Code Coverage for Eclipse
JaCoCo Ant Tasks: Coverage
The Future of Code Coverage for Eclipse | © 2010 by Marc R. Hoffmann | made available under the EPL v1.0
The Future of Code Coverage for Eclipse
JaCoCo Ant Tasks: Report
The Future of Code Coverage for Eclipse | © 2010 by Marc R. Hoffmann | made available under the EPL v1.0
The Future of Code Coverage for Eclipse
JaCoCo Ant Tasks: Report
The Future of Code Coverage for Eclipse | © 2010 by Marc R. Hoffmann | made available under the EPL v1.0
The Future of Code Coverage for Eclipse
Report Sorting
Project A
Project B
80%
35%
Sort Items by absolut amount of missed code.
The Future of Code Coverage for Eclipse | © 2010 by Marc R. Hoffmann | made available under the EPL v1.0
The Future of Code Coverage for Eclipse
JaCoCo in Eclipse
The Future of Code Coverage for Eclipse | © 2010 by Marc R. Hoffmann | made available under the EPL v1.0
The Future of Code Coverage for Eclipse
JaCoCo on JDT Test Suite
Credits: Olivier Thomann
The Future of Code Coverage for Eclipse | © 2010 by Marc R. Hoffmann | made available under the EPL v1.0
The Future of Code Coverage for Eclipse
Implementation Details
The Future of Code Coverage for Eclipse | © 2010 by Marc R. Hoffmann | made available under the EPL v1.0
The Future of Code Coverage for Eclipse
Implementation Strategies
J 010Compiler Class Loader
JVM
JVM Profiling
Source Offline On-the-Fly
Instrumentation
Byte Code
The Future of Code Coverage for Eclipse | © 2010 by Marc R. Hoffmann | made available under the EPL v1.0
The Future of Code Coverage for Eclipse
Java Agent
java.lang.instrumentIn-MemoryNo class file preprocessing
byte[] transform(ClassLoader loader,String className,Class<?> classBeingRedefined,ProtectionDomain protectionDomain,byte[] classfileBuffer)throws IllegalClassFormatException
The Future of Code Coverage for Eclipse | © 2010 by Marc R. Hoffmann | made available under the EPL v1.0
The Future of Code Coverage for Eclipse
Implementation and Packaging
Set of OSGi Bundles< 3,000 LOC< 400 KB
ASM
Ant
core
agent
report
ant
3rd Party Dependencies
The Future of Code Coverage for Eclipse | © 2010 by Marc R. Hoffmann | made available under the EPL v1.0
The Future of Code Coverage for Eclipse
Keep the Good Ideas of EMMA
Byte Code InstrumentationJRE and Platform Independent
Basic Block CoverageGood Tradeoff between Datails and Overhead
Using boolean[] Arrays for Probe StorageConcurrency PossibleSharing the Instance
The Future of Code Coverage for Eclipse | © 2010 by Marc R. Hoffmann | made available under the EPL v1.0
The Future of Code Coverage for Eclipse
Basic Block Coverage
ALOAD probearrayICONST probeidICONST_1BASTORE
ALOAD probearrayICONST probeidICONST_1BASTORE
The Future of Code Coverage for Eclipse | © 2010 by Marc R. Hoffmann | made available under the EPL v1.0
The Future of Code Coverage for Eclipse
Class Identity
IssuesMultiple Versions of the Same Class in one VMModified Classes over Time
Use CRC64 HashFits into Java long
The Future of Code Coverage for Eclipse | © 2010 by Marc R. Hoffmann | made available under the EPL v1.0
The Future of Code Coverage for Eclipse
Avoid Coverage Runtime Dependency
Object access = ... // Retrieve instance
Object[] args = new Object[3];args[0] = Long.valueOf(0x89f47a04b2881d38); // class idargs[1] = "com/example/MyClass"; // class nameargs[2] = Integer.valueOf(24); // probe count
access.equals(args);
boolean[] probes = (boolean[]) args[0];
Avoid Class Loading IssuesUse JRE APIs only!
The Future of Code Coverage for Eclipse | © 2010 by Marc R. Hoffmann | made available under the EPL v1.0
The Future of Code Coverage for Eclipse
How to Share an Object Instance?
The Challenge:
Share a given object instanceby using JDK APIs only.
Current Solutions:Object as System PropertyInstall Custom Handler with Java LoggingInstall Custom URL Protocol HandlerInstrumented JRE Class
The Future of Code Coverage for Eclipse | © 2010 by Marc R. Hoffmann | made available under the EPL v1.0
The Future of Code Coverage for Eclipse
Runtime Isolation
Eating one‘s own dog food:Run JaCoCo on JaCoCo?
Java Agent becomes part of the application classpath Rename classes in jacocoagent.jarduring build ☺
The Future of Code Coverage for Eclipse | © 2010 by Marc R. Hoffmann | made available under the EPL v1.0
The Future of Code Coverage for Eclipse
Runtime Isolation
The Future of Code Coverage for Eclipse | © 2010 by Marc R. Hoffmann | made available under the EPL v1.0
The Future of Code Coverage for Eclipse
JaCoCo Implementation Maxims
Test FirstKeep it simple and fastRelease Often and Consistent
Every Work Item released as Trunk Build
The Future of Code Coverage for Eclipse | © 2010 by Marc R. Hoffmann | made available under the EPL v1.0
The Future of Code Coverage for Eclipse
JaCoCo Status
Statement CoverageHTML, XML, CSV ReportsAnt TasksDocumentationAPIs not frozen yet!
3rd Party IntegrationsSonar Plug-in
The Future of Code Coverage for Eclipse | © 2010 by Marc R. Hoffmann | made available under the EPL v1.0
The Future of Code Coverage for Eclipse
Future Plans
Branch CoverageFiltersEclipse PluginMaven Integration
The Future of Code Coverage for Eclipse | © 2010 by Marc R. Hoffmann | made available under the EPL v1.0
The Future of Code Coverage for Eclipse
Get Involved
Download the Latest Build at http://www.eclemma.org/jacocoIntegrate it With Your
BuildWhatever Tool
Get in Touch forFeature RequestsBug ReportsContributions
The Future of Code Coverage for Eclipse | © 2010 by Marc R. Hoffmann | made available under the EPL v1.0
The Future of Code Coverage for Eclipse
Questions?
Thank You!
Top Related