32
Tél : +41 (0) 21 312 94 15 Fax : +41 (0) 21 312 94 16 www.octo.ch © OCTO 2013 Avenue du Théâtre 7 1005 Lausanne - SUISSE 1 October 26th, 2013 Make use of Sonar on your mobile developments - It’s easy and useful!

Soft shake 2013 - make use of sonar on your mobile developments

  • Upload
    rfelden

  • View
    3.145

  • Download
    2

Embed Size (px)

Citation preview

Page 1: Soft shake 2013 - make use of sonar on your mobile developments

Tél : +41 (0) 21 312 94 15Fax : +41 (0) 21 312 94 16www.octo.ch© OCTO 2013

Avenue du Théâtre 71005 Lausanne - SUISSE

1

October 26th, 2013

Make use of Sonar on your mobile developments- It’s easy and useful!

Page 2: Soft shake 2013 - make use of sonar on your mobile developments

Romain Felden: Java / Android developer

Cyril Picat: C++, iOS, Groovy/Grails developer

OCTO Technology

2

Who We Are

Sonar Android

Lint Plugin

Android Maven Plugin

Quality Analysis Tools for Android

Jenkins Quality Dashboard

iOS

Sonar Objective-C

Plugin

Romain Felden: Java / Android developer

Cyril Picat: C++, iOS, Groovy/Grails developer

OCTO Technology

Page 3: Soft shake 2013 - make use of sonar on your mobile developments

3

Agenda

QUALITY TOOLS ON MOBILE1

SONAR PLUGINS PRESENTATION2

3 HOW-TO & DEMO IOS

4 HOW-TO & DEMO ANDROID

5 CONCLUSION

Page 4: Soft shake 2013 - make use of sonar on your mobile developments

Sonar For the UninitiatedManage quality of your software

Across languages/platforms (> 20)Across projectsAcross timeAcross multiple axis/depths

A web app for (re)viewing, a back-end for analysis

4

Page 5: Soft shake 2013 - make use of sonar on your mobile developments

5

QUALITY TOOLS ON MOBILE

Agenda

1

Page 6: Soft shake 2013 - make use of sonar on your mobile developments

Quality Tools on Mobile

19xx

sloccount/cloc

ClangOCUnit (X

code 2)

2008First iOS

SDK

2007

GTM

2009

Code coverage (X

code 3)

GHUnit

2011

OCUnit (Xcode 4)

Code coverage (L

LVM)

Xcode plugin for J

enkins

2012

OCLint (Clang)

Quality analys

is on Je

nkins

Sonar Obj-C

2013

XCUnit / Bot (X

code 5)

TESTS QUALITY

Page 7: Soft shake 2013 - make use of sonar on your mobile developments

Quality Tools on Mobile

7

2012/06

v0.0.1- Basic

v0.2 - OCLint

2013/10

v0.3.1 -Tests

and

2013/07

Pull request

Sonar Objective-C

Plugin

coverage

metrics

Page 8: Soft shake 2013 - make use of sonar on your mobile developments

Quality Tools on Mobile

Emma (

last re

lease)

2008First Android SDK

2005 2009

JaCoCo (E

clEmma)

2011

Android Lint

2012

Quality Tools f

or Android

sonar-android-lin

t-plugin

20132004

Cobertur

a (firs

t relea

se)

2001

Checkst

yle

maven-android-plugin

Page 9: Soft shake 2013 - make use of sonar on your mobile developments

9

SONAR PLUGINS PRESENTATION

Agenda

2

Page 10: Soft shake 2013 - make use of sonar on your mobile developments

Sonar Plugins Features

10

Android iOS

Complexity √ X (*)

Design √ XDocumentation √ √

Duplications √ √Issues √ (140) √ (58)

Size √ √ (*)

Tests √ √

(*) integrated as issues

(*) only LOC and files

Page 11: Soft shake 2013 - make use of sonar on your mobile developments

Sonar Plugin Architecture

11

Sonar Core

xctool

Build

Measures/Issues integration

Quality management

Measures/Issues computation

Squ

id p

lugi

n

Sur

efire

se

nsor

Cob

ertu

ra

sens

or

OC

Lint

se

nsor

gcovr oclint

xcodebuild / xctool

run-

sona

r.sh

sona

r-ru

nner

Sonar

Sonar ObjC

Platform

Sonar Objective-C plugin

Page 12: Soft shake 2013 - make use of sonar on your mobile developments

Sonar Plugin Architecture

12

Sonar Core

Build

Measures/Issues integration

Quality management

Measures/Issues computation

Squ

id p

lugi

n

Sur

efire

pl

ugin

Son

ar A

ndro

id p

lugi

n

Sonar

Android Plugin

Platform

Find

bugs

pl

ugin

Che

ckst

yle

plug

in

JaC

oCo

plug

in

PM

Dpl

ugin

mavenant gradle

Page 13: Soft shake 2013 - make use of sonar on your mobile developments

Testing / Quality Tools Integration

13

Quality Unit TestingUnit TestingUnit Testing BDD UI TestingUI TestingUI TestingUI Testing

...

√ √ X X X X X X X

OC

Lint

OC

Uni

t /

XC

Uni

t

GH

Uni

t

GTM Kiw

i

UI

Aut

omat

ion

KIF

Fran

k /

UIS

pec

* * ** = in roadmap

Page 14: Soft shake 2013 - make use of sonar on your mobile developments

Testing / Quality Tools Integration

14

Unit and Integration Testing

Unit and Integration Testing

Unit and Integration Testing UI Quality checksQuality checksQuality checksQuality checks

√ √ √ √ √ √ √ √

JUni

t

Rob

otiu

m

Rob

olec

tric

UIA

utom

ator

Che

ckst

yle

PM

D

Find

bugs

Lint

Page 15: Soft shake 2013 - make use of sonar on your mobile developments

15

HOW-TO & DEMO

Agenda

3

Page 16: Soft shake 2013 - make use of sonar on your mobile developments

How-to

16

Install Sonar, Sonar Runner and Sonar Objective-C plugin

Install prerequisites (xctool, gcovr, oclint)

Configure your project

Run analysis

Page 17: Soft shake 2013 - make use of sonar on your mobile developments

Configure your project

17

Copy run-sonar.sh in your Xcode project root folder and make it executable

Copy sonar-project.properties in your Xcode project root folder

Edit the sonar-project.properties file to match your Xcode iOS/MacOS project

Page 19: Soft shake 2013 - make use of sonar on your mobile developments

sonar-project.properties

19

#  Project  descriptionsonar.projectKey=my-­‐projectsonar.projectName=My  projectsonar.projectVersion=1.0sonar.projectDescription=Fake  description  #  Path  to  source  directories  sonar.sources=srcDir1,srcDir2  #  Xcode  project  configuration  (.xcodeproj  or  .xcworkspace)sonar.objectivec.project=myApplication.xcodeproj  sonar.objectivec.appScheme=myApplicationsonar.objectivec.testScheme=myApplicationTests

Page 20: Soft shake 2013 - make use of sonar on your mobile developments

Run it!

20

>  ./run-­‐sonar.sh

Page 21: Soft shake 2013 - make use of sonar on your mobile developments

Jenkins Quality Dashboard

21

Almost feature complete

No code checks

Time-consuming, error prone and intrusive

Weak reporting and configuration

Page 22: Soft shake 2013 - make use of sonar on your mobile developments

How-to using maven

22

Install Sonar and Sonar Android plugin

Run analysis

Connect ADB in root mode

Add maven profile(s) to your module(s)

Page 23: Soft shake 2013 - make use of sonar on your mobile developments

Maven structure

23

Parent module

Application module

Library module

Integration testing module

Page 24: Soft shake 2013 - make use of sonar on your mobile developments

Demo

24

Morse Flash

https://github.com/jayway/maven-android-plugin-samples

Page 25: Soft shake 2013 - make use of sonar on your mobile developments

Maven profilesparent module

25

<profile> <id>sonar</id> <modules> <module>morse-lib</module> <module>morseflash-app</module> <module>morseflash-instrumentation</module> </modules>

<properties> <sonar.profile>Android Lint</sonar.profile> <sonar.jacoco.excludes>*test*</sonar.jacoco.excludes> <sonar.jacoco.itReportPath>target/jacoco-it.exec</sonar.jacoco.itReportPath> <sonar.jacoco.reportPath>jacoco.exec</sonar.jacoco.reportPath> <sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin> <sonar.skippedModules>morseflash-instrumentation</sonar.skippedModules> <sonar.exclusions>**/org/jacoco/**</sonar.exclusions> <jacoco.version>0.6.2.201302030002</jacoco.version> </properties>

<dependencyManagement> <dependencies> <dependency> <groupId>org.jacoco</groupId> <artifactId>org.jacoco.agent</artifactId> <version>${jacoco.version}</version> <classifier>runtime</classifier> </dependency> </dependencies> </dependencyManagement> <build> <pluginManagement> <plugins> <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>${jacoco.version}</version> </plugin> </plugins> </pluginManagement> </build></profile>

Page 26: Soft shake 2013 - make use of sonar on your mobile developments

Maven profilesapplication module (includes unit testing)

26

<profile> <id>sonar</id> <dependencies> <dependency> <groupId>org.jacoco</groupId> <artifactId>org.jacoco.agent</artifactId> <classifier>runtime</classifier> <scope>compile</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <executions> <execution> <id>instrument-classes</id> <goals> <goal>instrument</goal> </goals> <configuration> <excludes> <exclude>*test*</exclude> <exclude>*/test/*</exclude> </excludes> </configuration> </execution> <execution> <id>restore-instrumented-classes</id> <phase>package</phase> <goals> <goal>restore-instrumented-classes</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>com.jayway.maven.plugins.android.generation2</groupId> <artifactId>android-maven-plugin</artifactId> <configuration> <test> <coverage>true</coverage> <createReport>true</createReport> </test> </configuration> <extensions>true</extensions> </plugin> </plugins> </build></profile>

Page 27: Soft shake 2013 - make use of sonar on your mobile developments

Maven profilesintegration testing module

27

<profiles> <profile> <id>sonar</id> <build> <plugins> <plugin> <groupId>com.jayway.maven.plugins.android.generation2</groupId> <artifactId>android-maven-plugin</artifactId> <configuration> <dex> <!-- Required for EMMA --> <noLocals>true</noLocals> </dex> <test> <coverage>true</coverage> <createReport>true</createReport> </test> </configuration> <executions> <execution> <id>pull-coverage</id> <phase>post-integration-test</phase> <goals> <goal>pull</goal> </goals> <configuration> <pullSource>/data/data/com.simpligility.android.morseflash/files/coverage.ec</pullSource> <pullDestination>${project.basedir}/../morseflash-app/target/jacoco-it.exec</pullDestination> </configuration> </execution> </executions> </plugin> </plugins> </build> </profile></profiles>

Page 28: Soft shake 2013 - make use of sonar on your mobile developments

Run it!

28

>  mvn  -­‐P  sonar  clean  install

>  mvn  -­‐P  sonar  sonar:sonar

Page 29: Soft shake 2013 - make use of sonar on your mobile developments

29

CONCLUSION

Agenda

5

Page 30: Soft shake 2013 - make use of sonar on your mobile developments

Why Use Sonar?

30

Mobile projects are small and short, is it applicable?

Three typical uses cases:

Small and short projects

Assessments

Bigger projects (there are!)

Page 32: Soft shake 2013 - make use of sonar on your mobile developments

Tél : +41 (0) 21 312 94 15Fax : +41 (0) 21 312 94 16www.octo.ch© OCTO 2013

Avenue du Théâtre 71005 Lausanne - SUISSE

32

Questions/Answers