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

F62f9fa404ff35e3c57f20cc16441c7b?s=128

Roch Delsalle

June 17, 2014
Tweet

Transcript

  1. Scala Code quality assurance by Roch Delsalle ScalaDays Berlin 2014

    @D_Roch
  2. 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.
  3. 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,
  4. Why it is worth it ? for safe production!

  5. it’s at your own risk in production!

  6. Why it is worth it? coding without bugs, really? Fail

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

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

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

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

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

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

    GRADLE Build automation MAVEN Software project management
  18. Code quality inspection HTML output

  19. 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>

  20. 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
  21. Code quality inspection results & interfaces

  22. External tools integration Sing sing sing PASSED WAITING FAILED GOD

    mode on Let’s pray What? no way!
  23. Possible workflow it’s your choice SCOVERAGE SCALA CODE COVERAGE build

    result analysis
  24. industrialisation don’t reapeat yourself Generate docs Generate API results for

    frontend developers
  25. deployment INDUSTRIALISATION put your hands in the air Magenta/Riff-Raff :

    The Guardian's scala-based deployment lib OR Capistrano-sbt
  26. Thank you any questions? ScalaDays Berlin 2014 @D_Roch

  27. Further reading keep the track!