Slide 1

Slide 1 text

Scala Code quality assurance by Roch Delsalle ScalaDays Berlin 2014 @D_Roch

Slide 2

Slide 2 text

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.

Slide 3

Slide 3 text

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,

Slide 4

Slide 4 text

Why it is worth it ? for safe production!

Slide 5

Slide 5 text

it’s at your own risk in production!

Slide 6

Slide 6 text

Why it is worth it? coding without bugs, really? Fail early... not in production Avoid repetitive tasks Increase your deployment velocity

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

Code Coverage techniques definition Line level coverage Branch level coverage Statement level coverage is always under construction T he road to success…

Slide 9

Slide 9 text

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?

Slide 10

Slide 10 text

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:

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

BRANCH LEVEL COVERAGE going everywhere If / else statements Match statements Partial function cases Try / catch / finally clauses

Slide 13

Slide 13 text

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…

Slide 14

Slide 14 text

Bytecode instrumentation Let’s rock! Using JVM Java Agent Done natively in the VM Notified at runtime when a statement is execution

Slide 15

Slide 15 text

Abstract syntax tree Scala’s way Need to write temporary files Runtime bytecode instrumentation works well for Java … not for Scala

Slide 16

Slide 16 text

scoverage, the modular choice scalability SCOVERAGE SCALA CODE COVERAGE scoverage.org github.com/scoverage Samuel Stephen https://github.com/sksamuel

Slide 17

Slide 17 text

Code instrumentation input Go on, Maestro! SBT Scala Build Tool GRADLE Build automation MAVEN Software project management

Slide 18

Slide 18 text

Code quality inspection HTML output

Slide 19

Slide 19 text

Code quality inspection XML output 
 
 
 /scoverage-samples/src/main/scala/com/sksamuel/scoverage/samples/Platform.scala
 com.sksamuel.scoverage.samples
 Platform
 Class
 <none>
 137
 374
 374
 12
 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
 })
 akka.actor.Props.apply


Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

Code quality inspection results & interfaces

Slide 22

Slide 22 text

External tools integration Sing sing sing PASSED WAITING FAILED GOD mode on Let’s pray What? no way!

Slide 23

Slide 23 text

Possible workflow it’s your choice SCOVERAGE SCALA CODE COVERAGE build result analysis

Slide 24

Slide 24 text

industrialisation don’t reapeat yourself Generate docs Generate API results for frontend developers

Slide 25

Slide 25 text

deployment INDUSTRIALISATION put your hands in the air Magenta/Riff-Raff : The Guardian's scala-based deployment lib OR Capistrano-sbt

Slide 26

Slide 26 text

Thank you any questions? ScalaDays Berlin 2014 @D_Roch

Slide 27

Slide 27 text

Further reading keep the track!