1. Code Quality Assurance
FH Technikum Wien, April 2013
Peter Kofler, ‘Code Cop’
@codecopkofler
www.code-cop.org
Copyright Peter Kofler, licensed under CC-BY.
2.
3. Peter Kofler
• Ph.D. (Appl. Math.)
• Professional Software
Developer for 14 years
• Lead Developer at IBM
• “fanatic about code quality”
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
4. The opinions expressed here are my
own and do not necessarily represent
those of current or past employers.
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
5. Tools of the Trade
●
Mindset/Books
●
Code Kata
●
TDD/BDD
●
Code Coverage
●
CI
●
Static Analysis
●
Code Review
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
19. What Exactly Will We Do?
●
write code together
●
using TDD
●
see techniques
and patterns
●
discuss while
doing
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
20. The Requirements.
• Write a class named “PrimeFactors”
that has one static method: generate.
● The generate method takes an integer
argument and returns a List<Integer>.
● That list contains the prime factors in
numerical sequence.
http://butunclebob.com/ArticleS.UncleBob.ThePrimeFactorsKata
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
21. First Some Math.
●
Prime Number: number > 1 that has
no divisors other than 1 and itself.
●
e.g. 2, 3, 5, 61, 67, ..., 997, ..., 243112609
-1
●
Prime Factors: prime numbers that
divide an integer without remainder.
●
e.g. 2 = 2,
4 = 2 * 2,
24 = 2 * 2 * 2 * 3
288 = 25
* 32
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
22. Requirements (for Mortals).
• code a file/module/class “PrimeFactors”
• function/method/routine “generate“
• accept an integer number as parameter
• return the prime factors of that number
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
25. Unit Testing
• test individual units
• isolate each part
• show that the individual parts are
correct
• regression testing
• sort of living documentation
• executed within a framework
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
27. Some xUnit Frameworks
● Smalltalk – SUnit
● Java - JUnit, TestNG
● .NET - NUnit, Typemock
● C++ - CppUTest
● Groovy, PHP, Python, Ruby, Scala, ...
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
28. “I write unit tests for one
reason: so my coworkers
don't f*** up my code.”
(David Angry)
29. Test-Driven Development
●
add a test
●
run all tests and see if the new one fails
●
write some code
●
run all tests and see them succeed
●
refactor code mercilessly
●
„Red Green Refactor“
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
33. Scenarios and Stories
focus on behaviour
(e.g. requirements are behaviour)
full sentences
expected behaviour should
Use Arrange-Act-Assert in form of
Given-When-Then
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
49. Continuous Integration
• Maintain a code repository
• Automate the build
• Make the build self-testing
• Everyone commits every day
• Every commit should be built
• Keep the build fast
• Everyone can see the results of the build
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
62. Some Code Review Tools
●
Your peer (Pair Programming)
●
Your version control system
●
Your IDE (e.g. ReviewClipse)
●
Commercial products
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
63.
64. Lessons Learned
(!) Boy Scout Rule
(!) Do TDD/BDD
(!) Use the Tools
(Coverage, CI, Static Analysis)
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY