Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

How to improve code quality for iOS apps?

629 views

Published on

The deck contains a few ideas how to improve iOS apps code quality using continuous inspection and unit testing

Published in: Technology
  • Be the first to comment

How to improve code quality for iOS apps?

  1. 1. How to improve Code Quality? iOS apps RECOMMENDATIONS
  2. 2. Code Quality Continuous Inspection Unit Testing 2
  3. 3. Sonar covers the 7 axes of code quality SONAR an open source web application to manage code quality
  4. 4. Key metrics  Potential bugs  Potential performance problems  Potential security issues  Duplicates  Unused Code  Code Complexity  Technical debt  Сoverage
  5. 5. Community Plugin 5 FREE No support Might not support Xcode 8 https://github.com/Backelite/sonar- objective-c
  6. 6. Official Plugin 6 € 5,000 per year Support included Frequent new releases http://www.sonarsource.com/products/plugi ns/languages/objective-c/
  7. 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. 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. 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. 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. 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. 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() } }

×