6. Official Plugin
6
€ 5,000 per year
Support included
Frequent new releases
http://www.sonarsource.com/products/plugi
ns/languages/objective-c/
7. Comparison
community plugin official plugin
price Free € 5,000 per year
support no included
metrics •Complexity: uses Lizard
•Documentation: blank comments, comment
lines, %
•Duplication: blocks, linkes, %
•Issues: Uses OCLint: 63 rules, and Faux Pas: 102
rules
•Size
•Test: Uses xctool, will probably switch to
xcodebuild + xcpretty soon
•Code coverage: With gcovr for project before
Xcode 7, otherwise slather
more details: https://github.com/octo-
technology/sonar-objective-
c/wiki/Features, https://github.com/Backelite/son
ar-objective-c
200+ rules: details
supported
systems
•Given that there is no official support, POC is
required to check it whether it works with XCode
8
•0.4.x releases for SonarQube >= 4.3 (4.x and 5.x)
•latest release was in 01/2015
•no information about XCode
supported
•all Sonar versions are
supported
8. Recommendations
Configure Objective C and Swift
community plugins
Set up daily scans
Configure daily emails
to the dev team
Analyze results
•Define areas for improvements:
•Security, unused code, code
duplicates, potential performance
issues
•Reduce code complexity
•Fix existing critical and major issues
Fix new issues
8
If community plugins don’t work - buy an official plugin
9. Metrics and KPIs to track
Track Issues provided by plugin:
◦ fix blockers and majors
◦ set an acceptable threshold for minor and info
Track the next metrics:
◦ technical debt (calculated by the tool)
◦ security issues
◦ unit test coverage
◦ duplicated code
◦ complexity:
◦ cyclomatic complexity number
◦ number of parameters
10. Unit Testing
Don’t test trivial code!
Scope of Unit Testing:
◦ View Models
◦ Generic Algorithms
◦ Managers with business logic
◦ Complicated View Controllers
Expected incremental coverage is ~60%
◦ Code coverage is not a primary goal for unit testing!
Tools:
◦ XCTest
◦ Sonar
◦ Jenkins – add unit tests to build lifecycle
10
11. Unit testing –
Process recommendations
Write unit tests
for the code to
be refactored
Write unit tests
during bug
fixing
Start unit
testing for the
new code
11
12. Exampleofaunittest
12
class LabelValuesTests: XCTestCase {
var vc: ViewController!
override func setUp() {
super.setUp()
let storyboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
vc = storyboard.instantiateInitialViewController() as! ViewController
}
func testLabelValuesShowedProperly() {
vc.updateLabels(Float(80.0), Float(50.0), Float(40.0))
// The labels should now display 80, 50 and 40
XCTAssert(vc.numberLabel.text == "80.0", "numberLabel doesn't show the right text")
XCTAssert(vc.percentageLabel.text == "50.0%", "percentageLabel doesn't show the right text")
XCTAssert(vc.resultLabel.text == "40.0", "resultLabel doesn't show the right text")
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the
class.
super.tearDown()
}
}
Notas del editor
FREE: Track your iOS app code quality using Sonar: http://blog.octo.com/en/track-your-ios-application-code-quality-using-sonar/community plugin: https://github.com/Backelite/sonar-objective-c
NOT FREE: SonarSource Objective-C
http://www.sonarsource.com/products/plugins/languages/objective-c/
Documentation: http://docs.sonarqube.org/pages/viewpage.action?pageId=3080359
Automated Objective-C code quality analysis
200+ coding rules
Coding rules for MISRA-C and MISRA-C++
MITRE CWE coverage
CWE Compatible
Support for user-defined coding rules