Continuous Integration Improving Software Quality with Continuous Integration Continuous Integration In a nutshell Continuous Integration (CI) is: Assembling software every time code changes CI is important because: Integrating software often decreases the life-span of a defect Build Better Code Faster 2007, Stelligent Incorporated 2
Continuous Integration in Practice Continuous Integration requirements: A reliable build process Ant, Maven, etc An SCM system Subversion, Perforce, CVS, etc A Continuous Integration server CruiseControl, Hudson, etc 2007, Stelligent Incorporated 3 Life with Continuous Integration 1. Developer checks out working copy of code a. Makes modifications & runs local build i. Does an update 2. If build was successful, checks in modifications 3. Moves on to next task 2007, Stelligent Incorporated 4
Life with Continuous Integration CI server is always listening 1. If SCM is modified a. CI server assembles software i. If assembly fails, CI server notifies interested parties b. CI server posts results and resumes listening 2007, Stelligent Incorporated 5 Continuous Integration Implemented 2007, Stelligent Incorporated 6
Successful CI Process Three prevailing principles: 1. Expand the definition of software defect 2. Ensure a short lifetime for defects introduced 3. Extend defect visibility for all stakeholders 2007, Stelligent Incorporated 7 What is a Defect? Is it just not meeting the specification? Yes, but specifications can be hard to nail down Can t validate them until later cycles Expand definition of defect Create specific gates Exercise gates earlier 2007, Stelligent Incorporated 8
Expanding Defect Definition Finer grained: Developer tests didn t pass Developer tests weren t written Code coverage dropped Code complexity increased Coverage dropped and complexity increased! 2007, Stelligent Incorporated 9 Ensuring Short Defect Lifecycle Broaden the value of a build No longer just a compilation process: 1. Compile 2. Test 3. Inspect 4. Deploy 2007, Stelligent Incorporated 10
Broad Software Builds Broad software builds act as quality gates Inexpensive Continuous Rapid 2007, Stelligent Incorporated 11 Broad Builds Increase Visibility Visibility is transparency What code changed? Who changed that code? How well was the code tested? How complex was the code? 2007, Stelligent Incorporated 12
Broadening the Build Process Testing is obvious, right? Does assume people author them! For every build, execute developer tests Test failure is a build failure Monitor test velocity as well 2007, Stelligent Incorporated 13 Software Inspections Code reviews are excellent, but Manual Error prone Disappear when schedules are tight Humans focus on high level details Machines focus on low level details 2007, Stelligent Incorporated 14
Software Inspections Machines make code reviews more effective Cheap to obtain and run Many open source tools available Need CPUs to parse files Output is objective Interpretation is subjective 2007, Stelligent Incorporated 15 Software Inspection Categories Five primary groups: Complexity Duplication Dependencies Coding standards Code coverage 2007, Stelligent Incorporated 16
Code Complexity Complexity correlates to errors Cyclomatic complexity Measures paths through code More paths increase cost to test Decrease comprehensibility 2007, Stelligent Incorporated 17 Java JavaNCSS PMD Code Complexity Tools 2007, Stelligent Incorporated 18
Code Duplication Duplicate code can replicate: Defects Poor design & coding Unknown duplication will haunt you 2007, Stelligent Incorporated 19 Java CDP Simian Code Duplication Tools 2007, Stelligent Incorporated 20
Dependencies Understanding code dependencies Facilitates understanding LOE to change Brittleness 2007, Stelligent Incorporated 21 Java JDepend Dependency Tools 2007, Stelligent Incorporated 22
Coding Standards Standards can Enforce consistency Increase comprehensibility Decrease defects via common defect patterns 2007, Stelligent Incorporated 23 Coding Standards Tools Java Check Style PMD 2007, Stelligent Incorporated 24
Code Coverage Measuring code coverage Facilitates understanding what s not tested Promotes collaboration between development and QA 2007, Stelligent Incorporated 25 Java Cobertura Clover Code Coverage Tools 2007, Stelligent Incorporated 26
Extending Visibility Run inspections often & publish results Cheap quality gates Foster accountability Cultivate collaboration You can t improve what you can t measure 2007, Stelligent Incorporated 27 Thank you! Check out www.testearly.com www.thediscoblog.com Continuous Integration: Improving Software Quality and Reducing Risk, June 2007 2007, Stelligent Incorporated 28
Andrew Glover aglover@stelligent.com Blogs: www.testearly.com www.integratebutton.com www.thediscoblog.com