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

Leveraging Xcode Code Coverage

Leveraging Xcode Code Coverage

Learn how to exploit Xcode Code Coverage information using the latest tools from Apple and the community.

3f309c992e2b1a5c3c014e63810a2f68?s=128

Simone Civetta

July 13, 2015
Tweet

Transcript

  1. Leveraging Xcode Code Coverage Simone Civetta Monday, 13th July -

    Minsk, Belarus
  2. What is Code Coverage?

  3. Testing

  4. Metric that measures the value of your tests

  5. Code Coverage detects ☞ Which code is executing when we're

    running the tests ☞ Which code is untested
  6. How does it work? ☞ The information is gathered in

    two steps ☞ compile time ☞ runtime ☞ Tools count each expression that is executed
  7. Code coverage on iOS

  8. Code coverage on iOS until last month

  9. None
  10. Objective-C

  11. Swift

  12. Swift

  13. None
  14. How it worked ☞ LLVM creates annotation and data files:

    ☞ .gcno ☞ .gcda
  15. How to enable in Xcode

  16. None
  17. None
  18. How to enable via command line

  19. GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES GCC_GENERATE_TEST_COVERAGE_FILES=YES xcodebuild [...] test

  20. Tools

  21. Tools ☞ Coverstory ☞ gcovr ☞ lcov ☞ Slather

  22. Slather Exports to: - HTML - Gutter JSON - Cobertura

    XML github.com/venmo/Slather
  23. But, also

  24. Swiftcov swiftcov github.com/realm/SwiftCov ☞ Supports gcov format ☞ Uses breakpoints

    to gather coverage data
  25. None
  26. Code coverage on iOS

  27. Code coverage on iOS since last month

  28. None
  29. Objective-C

  30. Swift

  31. A new format ☞ gcov ☞ profdata

  32. Xcode generates profdata files for ☞ Swift ☞ ...and Objective-C

  33. How to enable in Xcode

  34. None
  35. None
  36. None
  37. How to enable via command line

  38. xcodebuild [...] test -enableCodeCoverage YES

  39. xcodebuild -scheme MoDevByProject -destination "name=iPhone 6,OS=latest" -enableCodeCoverage YES test

  40. Exploiting the data ☞ llvm-cov

  41. Exploiting the data $XCODE_PATH/Toolchains/XcodeDefault.xctoolchain/usr/bin/llvm-cov show -instr-profile MY_PROJECT_PROFDATA MY_PROJECT_BINARY_FILE

  42. None
  43. Tools

  44. Tools ☞ Slather ☞ Xcode Server

  45. Slather github.com/venmo/slather/pull/92

  46. Xcode Server

  47. None
  48. None
  49. Summing up

  50. Doesn't tell you if your code is bad ...

  51. None
  52. None
  53. Doesn't tell you if your code is bad But can

    help writing better code
  54. You're just minutes away from collecting Code Coverage info for

    Swift Start soon!
  55. Thank you

  56. Simone Civetta @viteinfinite Xebia IT Architects