Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Code Coverage by Sachin Vas

Code Coverage by Sachin Vas

Swift Bangalore Chapter #18

Swift India

October 19, 2019
Tweet

More Decks by Swift India

Other Decks in Programming

Transcript

  1. CODE COVERAGE
    Sachin Vas, Halodoc

    View Slide

  2. View Slide

  3. AGENDA
    ▸ CI/CD PIPELINES
    ▸ CODE COVERAGE
    ▸ XCODE IDE SUPPORT
    ▸ LLVM CODE COVERAGE

    View Slide

  4. Code Merge
    Build Unit Test Integration Test
    Code Review Staging Production
    CI Pipeline
    CD Pipeline

    View Slide

  5. CI/CD
    ▸ Merges changes to main branch as often as possible
    ▸ Validates changes using automated tests
    ▸ Added advantage over delayed merges which usually
    ends up in integration hell
    ▸ Always checks newer commits doesn’t break any of the
    existing code
    CI PIPELINE

    View Slide

  6. CI/CD
    ▸ Extension on the previous step
    ▸ Release new changes quickly in a sustainable way
    ▸ Deploy at your convenience time (daily, weekly, fortnightly)
    ▸ Best practice is to rollout updates in small batches for ease
    troubleshooting any production issues.
    ▸ Continuous Deployment is the automatic version of
    Continuous Delivery.
    CD PIPELINE

    View Slide

  7. CODE COVERAGE
    ▸ What
    ▸ Why
    ▸ How
    ▸ Types
    CODE COVERAGE

    View Slide

  8. CODE COVERAGE
    ▸ Percentage of code covered by automated tests
    ▸ Determines which statements are executed
    ▸ Part of feedback loop
    WHAT?

    View Slide

  9. CODE COVERAGE
    ▸ Our tests actually test our code
    ▸ Do we have enough testing in place
    ▸ Maintain Test Quality over the lifetime of a project
    WHY?

    View Slide

  10. CODE COVERAGE
    ▸ Source Code Instrumentation
    ▸ Intermediate Code Instrumentation
    ▸ Runtime Information collection
    HOW?

    View Slide

  11. CODE COVERAGE
    ▸ Statement
    ▸ Branch
    ▸ Function
    TYPES

    View Slide

  12. CODE COVERAGE
    CODE COVERAGE PERCENTAGE

    View Slide

  13. CODE COVERAGE
    ▸ Built into the IDE
    ▸ Provides line coverage metrics
    ▸ You can exercise your frameworks (only open source files)
    ▸ You can customise running certain TestBundles on Certain
    Targets
    XCODE CODE COVERAGE

    View Slide

  14. CODE COVERAGE
    DEMO

    View Slide

  15. LLVM-COV
    ▸ llvm-cov
    ▸ Provides 4 types of code coverage
    ▸ Sub commands for meaningful statistics
    ▸ Custom script to generate coverage
    ▸ Provides similar reports as Jacuco.
    LLVM CODE COVERAGE

    View Slide

  16. LLVM-COV
    ▸ llvm-profdata
    ▸ Merge multiple Profile Data Files
    ▸ Useful if you have multiple in-house frameworks
    LLVM PROFDATA COVERAGE

    View Slide

  17. LLVM-COV
    DEMO

    View Slide

  18. CODE COVERAGE
    ▸ Ensure every Public Method is covered
    ▸ Increase Code Coverage for each Public Method
    ▸ Cover Conditionals
    ▸ Prefer Branch Coverage over other types
    RECOMMENDATION

    View Slide

  19. CODE COVERAGE
    https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/testing_with_xcode/chapters/
    07-code_coverage.html
    https://clang.llvm.org/docs/SourceBasedCodeCoverage.html
    https://llvm.org/docs/CommandGuide/llvm-cov.html
    https://llvm.org/docs/CommandGuide/llvm-profdata.html
    REFERENCES

    View Slide