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

Post on 22-May-2015

3,144 views 2 download

Tags:

transcript

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!

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

3

Agenda

QUALITY TOOLS ON MOBILE1

SONAR PLUGINS PRESENTATION2

3 HOW-TO & DEMO IOS

4 HOW-TO & DEMO ANDROID

5 CONCLUSION

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

5

QUALITY TOOLS ON MOBILE

Agenda

1

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

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

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

9

SONAR PLUGINS PRESENTATION

Agenda

2

Sonar Plugins Features

10

Android iOS

Complexity √ X (*)

Design √ XDocumentation √ √

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

Size √ √ (*)

Tests √ √

(*) integrated as issues

(*) only LOC and files

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

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

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

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

15

HOW-TO & DEMO

Agenda

3

How-to

16

Install Sonar, Sonar Runner and Sonar Objective-C plugin

Install prerequisites (xctool, gcovr, oclint)

Configure your project

Run analysis

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

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

Run it!

20

>  ./run-­‐sonar.sh

Jenkins Quality Dashboard

21

Almost feature complete

No code checks

Time-consuming, error prone and intrusive

Weak reporting and configuration

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)

Maven structure

23

Parent module

Application module

Library module

Integration testing module

Demo

24

Morse Flash

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

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>

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>

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>

Run it!

28

>  mvn  -­‐P  sonar  clean  install

>  mvn  -­‐P  sonar  sonar:sonar

29

CONCLUSION

Agenda

5

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!)

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