Share
Embed
Scala Code Quality Assurance - ScalaIO Paris
ScalaIO 2014 - Paris
Roch Delsalle
Mister Bell
Roch Delsalle
October 24, 2014
Transcript
34 slides
-
about me and Mister Bell Scala lead developer Specialist in
REST API Specialist in continuous integration Code alchemist Roch Delsalle Leader in performance and mobile affiliation in Europe, Latin America and the region of the Middle East. -
what is a quality assurance process? yes, what is it
? Simply, the Automation of repetitive quality check tasks my slime is quality! Don’t laugh, -
Why it is worth it? coding without bugs, really? Fail
early... not in production Avoid repetitive tasks Increase your deployment velocity -
Continuous Integration the runner Jenkins Fork of Hudson M.I.T. License
Self hosted solution Open source gitlab Self hosted solution Open Source travis Hosted solution Open Source -
Code Coverage techniques definition Line level coverage Branch level coverage
Statement level coverage is always under construction T he road to success… -
statement level coverage Cover it all val status = if
(age < 18) "No beer" else "Beer for you” If you test: age = 18 You would get: Lines covered : 100 % Statements covered : 50 % Doh! a free beer? -
Line level VS Branch level ready? fight! 4 out of
5 lines covered : 80 % 1 out of 2 branches covered : 50 % if(cond) { line1 line2 line3 line4 } else { line5 } If your test only goes in the cond being true and never runs the else branch : You would have: -
Statement level coverage vs Branch round 2, fight! Statements covered
: 100 % Branches covered : 50 % def testMe(cond1:Boolean, cond2:Boolean) = { if (cond1) line1() if (cond2) line2() } If your test only goes in the cond1 being true and cond2 being true: You would have: -
Statement level coverage vs Branch round 2, fight! Statements covered
: 100 % Branches covered : 50 % def testMe(cond1:Boolean, cond2:Boolean) = { if (cond1) line1() if (cond2) line2() } If your test only goes in the cond1 being true and cond2 being true: You would have: In order to get 100% branches covered, you will have to add a test with cond1 and cond2 as false -
BRANCH LEVEL COVERAGE going everywhere If / else statements Match
statements Partial function cases Try / catch / finally clauses -
Scala code coverage Tools recap SCCT jacoco4sbt Scoverage line level
coverage YES YES YES statement coverage NO NO YES branch coverage NO YES YES Instrumentation AST Bytecode AST need some beer… -
Bytecode instrumentation Java only Using JVM Java Agent Done natively
in the VM Notified at runtime when a statement is execution -
Bytecode instrumentation Java only Scala bytecode output is more complex
Not reliable for instrumentation -
Bytecode instrumentation Java only Let’s say you are using line
level coverage for this example You write two lines of Scala 1rst line compiles to 100 bytecodes 2d line compiles to 10 bytecodes If you have only tested line 2 you would get 9% coverage, when it should be 50% -
Abstract syntax tree Scala’s way Need to write temporary files
Runtime bytecode instrumentation works well for Java … not for Scala -
scoverage, the modular choice scalability SCOVERAGE SCALA CODE COVERAGE scoverage.org
github.com/scoverage Samuel Stephen https://github.com/sksamuel -
Code instrumentation input Go on, Maestro! SBT Scala Build Tool
GRADLE Build automation MAVEN Software project management -
Code quality inspection XML output <?xml version="1.0"?> <statements> <statement> <source>/scoverage-samples/src/main/scala/com/sksamuel/scoverage/samples/Platform.scala</source>
<package>com.sksamuel.scoverage.samples</package> <class>Platform</class> <classType>Class</classType> <method><none></method> <id>137</id> <start>374</start> <end>374</end> <line>12</line> <description>akka.actor.Props.apply({ scoverage.Invoker.invoked(135, "/scoverage-samples/target/scala-2.11/scoverage-data"); classOf[com.sksamuel.scoverage.samples.OrderEngine] }, { scoverage.Invoker.invoked(136, "/scoverage-samples/target/scala-2.11/scoverage-data"); Platform.this.creditEngine })</description> <symbolName>akka.actor.Props.apply</symbolName> -
Static Code AnalYSERS results & interfaces • Scapegoat • FindBugs
• checkstyle • ScalaStyle -
Code quality inspection results & interfaces SonarQUBE Scala Sonar Tool
https://github.com/SonarCommunity/sonar-scala -
Code quality inspection Sonar Scoverage Plugin Statement level coverage Branch
level coverage + SCOVERAGE SCALA CODE COVERAGE = Radoslav Buranský http://buransky.com results & interfaces -
Possible workflow our choice SCOVERAGE SCALA CODE COVERAGE build result
analysis Scala Backend JS FRONTEND -
External tools integration Sing sing sing PASSED WAITING FAILED GOD
mode on Let’s pray What? no way! -
industrialisation don’t reapeat yourself Generate docs Generate API results for
frontend developers -
deployment INDUSTRIALISATION put your hands in the air capistrano-sbt Deploy
your apps To any number of machines https://github.com/yyuu/capistranosbt -
deployment INDUSTRIALISATION put your hands in the air Magenta/Riff-Raff :
The Guardian's scala-based deployment lib OR Capistrano-sbt