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

Scala Code Quality Assurance - ScalaDays Berlin

Scala Code Quality Assurance - ScalaDays Berlin

ScalaDays 2014 - Berlin
Roch Delsalle
Mister Bell

Roch Delsalle

June 17, 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: In order to get 100% branches covered, you will have to add a test with cond1 and cond2 as false
  9. BRANCH LEVEL COVERAGE going everywhere If / else statements Match

    statements Partial function cases Try / catch / finally clauses
  10. 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…
  11. Bytecode instrumentation Let’s rock! Using JVM Java Agent Done natively

    in the VM Notified at runtime when a statement is execution
  12. Abstract syntax tree Scala’s way Need to write temporary files

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

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

    GRADLE Build automation MAVEN Software project management
  15. 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>

  16. Code quality inspection One more thing… SonarQUBE Scala Sonar Tool

    Line level coverage Sonar Scoverage Plugin Statement level coverage Branch level coverage + SCOVERAGE SCALA CODE COVERAGE = Radoslav Buranský http://buransky.com
  17. deployment INDUSTRIALISATION put your hands in the air Magenta/Riff-Raff :

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