Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Scala Code Quality Assurance - ScalaIO Paris

Scala Code Quality Assurance - ScalaIO Paris

ScalaIO 2014 - Paris
Roch Delsalle
Mister Bell

Roch Delsalle

October 24, 2014
Tweet

More Decks by Roch Delsalle

Other Decks in Programming

Transcript

  1. 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.
  2. 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,
  3. Why it is worth it? coding without bugs, really? Fail

    early... not in production Avoid repetitive tasks Increase your deployment velocity
  4. 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
  5. Code Coverage techniques definition Line level coverage Branch level coverage

    Statement level coverage is always under construction T he road to success…
  6. 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?
  7. 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:
  8. 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:
  9. 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
  10. BRANCH LEVEL COVERAGE going everywhere If / else statements Match

    statements Partial function cases Try / catch / finally clauses
  11. 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…
  12. Bytecode instrumentation Java only Using JVM Java Agent Done natively

    in the VM Notified at runtime when a statement is execution
  13. 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%
  14. Abstract syntax tree Scala’s way Need to write temporary files

    Runtime bytecode instrumentation works well for Java … not for Scala
  15. scoverage, the modular choice scalability SCOVERAGE SCALA CODE COVERAGE scoverage.org

    github.com/scoverage Samuel Stephen https://github.com/sksamuel
  16. Code instrumentation input Go on, Maestro! SBT Scala Build Tool

    GRADLE Build automation MAVEN Software project management
  17. 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>&lt;none&gt;</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>

  18. Code quality inspection results & interfaces SonarQUBE Scala Sonar Tool

    https://github.com/SonarCommunity/sonar-scala
  19. Code quality inspection Sonar Scoverage Plugin Statement level coverage Branch

    level coverage + SCOVERAGE SCALA CODE COVERAGE = Radoslav Buranský http://buransky.com results & interfaces
  20. deployment INDUSTRIALISATION put your hands in the air capistrano-sbt Deploy

    your apps To any number of machines https://github.com/yyuu/capistranosbt
  21. deployment INDUSTRIALISATION put your hands in the air Magenta/Riff-Raff :

    The Guardian's scala-based deployment lib OR Capistrano-sbt