コードカバレッジとの付き合い方を知ってテストを書く

 コードカバレッジとの付き合い方を知ってテストを書く

Aaf94d61dec57d1c3cf2de7c09e472d4?s=128

Daiki Katayama

April 10, 2019
Tweet

Transcript

  1. ίʔυΧόϨοδͱͷ෇͖߹͍ํ Λ஌ͬͯςετΛॻ͘ 2019/04/10 Otemachi.swift #3 kariad/͔Γ͋Ͳ(@kariad_uu) 1

  2. ࣗݾ঺հ • kariad / @kariad_uu • ยࢁ େथ • ΦΠγοΫεɾϥɾେ஍

    iOS App Developer • / / V / ςετ / ઃܭ 2
  3. ίʔυΧόϨοδܭଌͯ͠·͔͢ʁ 3

  4. • ΧόϨοδ͸100%ͳΒ
 શ෦ςετͰ͖͍ͯͯେৎ෉ɺ
 
 Ͱ͸ͳ͍…ʂ

  5. ΧόϨοδͷछྨʹΑΔ໰୊

  6. ΧόϨοδʹ͸छྨ͕͋Δ • εςʔτϝϯτΧόϨοδ(C0) • ϒϥϯνΧόϨοδ(C1) • ίϯσΟγϣϯΧόϨοδ(C2)౳

  7. εςʔτϝϯτΧόϨοδ • ໋ྩจͷ௨ա཰

  8. x: 2, y: 2ͷ1έʔεͰΧόϨοδ100%

  9. ϒϥϯνΧόϨοδ • ෼ذͷ໢ཏ཰

  10. (x: 2, y: 2), (x: 0, y: 0)ͷ2έʔεͰΧόϨοδ100%

  11. • εςʔτϝϯτΧόϨοδ͸Ͳͷ ifจʹ΋ೖΒͳ͍ೖྗ͕ͳͯ͘΋ 100% ➡ શ໢ཏͱ͍͏؍఺Ͱ͸࿙Ε͕͋Δ

  12. x: 0, y: 0͸ͳͯ͘΋100%

  13. • XcodeͰܭଌͰ͖Δͷ͸εςʔτ ϝϯτΧόϨοδ(ϥΠϯΧό Ϩοδ) • JaCoCo΍Jest͸ϒϥϯνΧόϨο δ͕औΕΔ…

  14. ΧόϨοδͰ͸ ݟΔ͜ͱ͕Ͱ͖ͳ͍໰୊

  15. ΧόϨοδ100%Ͱ΋଍Γͳ͍෦෼ ςετͷೖྗ஋͕10ͩͱ৚͕݅5Ҏ্Ͱ΋੒ޭ͢Δ

  16. • ڥք஋෼ੳ • όά͕ى͖΍͍͢ͷ͸͜͏ݴͬͨ ڥքͷ෦෼ͳͷͰڥքʹண໨͢Δ

  17. ·ͱΊ • ΧόϨοδ100%Λͨͩ໨ࢦͯ͠΋ޮՌ͸൒ݮ • ΧόϨοδͷܭଌํ๏΍ڥք஋Λҙ্ࣝͨ͠ͰՁ ஋ͷ͋ΔςετΛॻ͜͏ • ଍Γ͍ͯΔࣄΛূ໌͸Ͱ͖ͳ͍͕ɺ଍Γ͍ͯͳ͍ ࣄ͸ূ໌Ͱ͖ΔͨΊɺΧόϨοδΛܭଌ͢Δ͜ͱ ͸େࣄ

  18. ٕज़ॻయ6 ͚11 https://techbookfest.org/event/tbf06/circle/54660004

  19. ͳͥεςʔτϝϯτΧόϨοδ ͚ͩͳͷ͔ • AppleͷυΩϡϝϯτʹ͸
 ʮCode coverage in Xcode is a

    testing option supported by LLVMʯ ➡ ΧόϨοδऔಘ͸LLVMͷػೳ https://developer.apple.com/library/archive/documentation/DeveloperTools/ Conceptual/testing_with_xcode/chapters/07-code_coverage.html
  20. ClangͷυΩϡϝϯτʹ͸ҎԼͷ 4͕ͭܭଌͰ͖Δͱॻ͍ͯ͋Δ • Function coverage • Instantiation coverage • Line

    coverage • Region coverage ClangͰ৭ʑऔΕΔͳΒಉ͡LLVM࢖͏SwiftͰ΋औΕͳ͍͔ͳ… https://clang.llvm.org/docs/SourceBasedCodeCoverage.html
  21. https://llvm.org/docs/ CoverageMappingFormat.html https://llvm.org/docs/CommandGuide/llvm- cov.html ͦͷଞࢀߟURL