Slide 1

Slide 1 text

CODE COVERAGE Sachin Vas, Halodoc

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

CODE COVERAGE ▸ What ▸ Why ▸ How ▸ Types CODE COVERAGE

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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?

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

CODE COVERAGE ▸ Statement ▸ Branch ▸ Function TYPES

Slide 12

Slide 12 text

CODE COVERAGE CODE COVERAGE PERCENTAGE

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

CODE COVERAGE DEMO

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

LLVM-COV DEMO

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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