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

XCTest(再)入門/reintroduction-to-xctest

 XCTest(再)入門/reintroduction-to-xctest

iOS Test Night #9 - 2周年 - での発表資料です。
https://testnight.connpass.com/event/102778/

Yusuke Hosonuma

December 10, 2018
Tweet

More Decks by Yusuke Hosonuma

Other Decks in Programming

Transcript

  1. Copyright (C) DeNA Co.,Ltd. All Rights Reserved. 9$5FTUʢ࠶ʣೖ໳ 1 iOS

    Test Night #9 - 2प೥- 2018/12/10ʢMonʣ 
 ࡉপ ༞հ@DeNA
  2. :VTVLF)PTPOVNB • ॴଐ ⁃ %F/"ɹ48&5άϧʔϓɹJ04ςετࣗಈԽνʔϜ • 'BWPSJUF ⁃  •

    ۙگ ⁃ ԶίϯEBZͰ2VJDLͷίʔυϦʔσΟϯάʹ͍ͭͯൃද ⁃ ϖϯΪϯଜͷ(JU)VCϦϙδτϦ͕ग़དྷͨ
 IUUQTHJUIVCDPNQFOHJONVSB Copyright (C) DeNA Co.,Ltd. All Rights Reserved. 3 @tobi462ʢτϏʣ ಈը΋ެ։ ϓϥΠϕʔτ։ൃ
  3. 6 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. • 6*ςετίʔυͷอकੑΛ্͛ΔϦϑΝΫλϦϯά5*14

    • 1SPQFSUZCBTFEUFTUJOHXJUI4XJGU$IFDL • 6*ςετͷ࣮ߦ࣌ؒͷ୹ॖʹ௅ઓ͢Δ • ࣮ફςετۦಈ։ൃJOJ04 • 2VJDL/JNCMFΛΑΓշదʹ࢖͏ͨΊʹ • 4XJGUʹ͓͚Δ.PDLϥΠϒϥϦͷ׆༻ • )551ϞοΫϥΠϒϥϦʮ.PDLJOHKBZʯΛ࢖ͬͯΈͨ࿩ • ιʔείʔυ͔ΒಡΈղ͘2VJDL͸ͲͷΑ͏ʹ࣮૷͞Ε͍ͯΔͷ͔ʁ ൃද͖ͯͨ͠΋ͷʢςετؔ܎ʣ
  4. 7 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. • 6*ςετίʔυͷอकੑΛ্͛ΔϦϑΝΫλϦϯά5*14

    • 1SPQFSUZCBTFEUFTUJOHXJUI4XJGU$IFDL • 6*ςετͷ࣮ߦ࣌ؒͷ୹ॖʹ௅ઓ͢Δ • ࣮ફςετۦಈ։ൃJOJ04 • 2VJDL/JNCMFΛΑΓշదʹ࢖͏ͨΊʹ • 4XJGUʹ͓͚Δ.PDLϥΠϒϥϦͷ׆༻ • )551ϞοΫϥΠϒϥϦʮ.PDLJOHKBZʯΛ࢖ͬͯΈͨ࿩ • ιʔείʔυ͔ΒಡΈղ͘2VJDL͸ͲͷΑ͏ʹ࣮૷͞Ε͍ͯΔͷ͔ʁ ൃද͖ͯͨ͠΋ͷʢςετؔ܎ʣ ͳΜ͔ςΫχΧϧͳ಺༰͕ଟ͍… ͋ΒͨΊͯΈΔͱ
  5. Nimble 12 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. ྫ୊ɿফඅ੫ࠐͷՁ֨ΛٻΊΔ

    func getPrice(_ price: Int) -> Double { return price * 1.05 } ջ͔͍͠ͷ࣌୅
  6. Nimble 18 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. खಈͰςετ͢Δ

    ͋ͬͯΔͬΆ͍Αʂ ͜Ε΋ཱ೿ͳςετ ͚ͩΕͲʜ
  7. Nimble 21 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. ྫ୊ɿফඅ੫ࠐͷՁ֨ΛٻΊΔʢ8%ʣ

    func getPrice(_ price: Int) -> Double { return price * 1.08 } ֹۚܭࢉͩ͠ҰԠಈ࡞֬ೝ͢Δ͔
  8. Nimble 22 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. खಈͰςετ͢Δ

    લճͷ1MBZHSPVOE͸࡟আͪ͠ΌͬͯͨͷͰ࡞Γ௚͠
  9. Nimble 24 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. खಈͰςετ͢Δ

    ஋͸ɾɾɾࠓճ΋͋ͬͯΔͳ ຖճɺ໨ࢹ֬ೝ΋໘౗ͩͳ… ϓϩάϥϜͰνΣοΫͪ͠Ό͑ ϓϩάϥϚ͸ʮଵଦʯ
  10. Nimble 30 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. ಠࣗͷςετࣗಈԽ

    ݁Ռ͕⭕ͱ❌ͰΘ͔Γ΍͘͢ग़Δʂ ͜ͷίʔυΛऔ͓͚ͬͯ͹ ࢓༷มߋͰͷ࠶ςετ΋ָͩ͠ ςετύλʔϯΛ૿΍͢ͷ΋ָͩʂ
  11. Copyright (C) DeNA Co.,Ltd. All Rights Reserved. • 1MBZHSPVOEʹ࢒͓͔ͯ͠ͳ͍ͱʜ •

    ࣗ෼ઐ༻ͳΜͩΑͳ͊ • ύλʔϯ૿͑ͯ͘Δͱɺ໨ࢹͰ΋ݟಀͦ͠͏ʜ ͚ͩͲ…
  12. Copyright (C) DeNA Co.,Ltd. All Rights Reserved. • 1MBZHSPVOEʹ࢒͓͔ͯ͠ͳ͍ͱʜ •

    ࣗ෼ઐ༻ͳΜͩΑͳ͊ • ύλʔϯ૿͑ͯ͘Δͱɺ໨ࢹͰ΋ݟಀͦ͠͏ʜ ͚ͩͲ… ඪ४తͳ࢓૊Έ͕͋Ε͹ ΈΜͳָ͕Ͱ͖Δͷʹͳ͊ɾɾɾ ͦΕ͕͋ΔΜͰ͢ʂ
  13. 35 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. • +6OJUͷొ৔

    • ୯ମςετࣗಈԽͷϑϨʔϜϫʔΫ • ଞͷݴޠʹ΋Ҡ২ʢ/6OJUɺ$QQ6OJUɺFUDʣ • Y6OJUϑΝϛϦʔͱݺ͹ΕΔ • J04 • 9$5FTUͱ͍͏໊લͰ xUnit ͷొ৔ ,FOU#FDL͕࡞ͬͨ 9$6OJUͰ͸μϝͩͬͨͷ͔ʁ
  14. 36 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. • Y6OJUͷొ৔Ͱ

    • ඪ४Խ͞Εͨ࿮૊Έ͕Ͱ͖ͨ • ςετίʔυͱͯ͠؅ཧͰ͖ΔΑ͏ʹ • ςετ͸ࢿ࢈Ͱ͋Δͱ͍͏ߟ͑ํʹ xUnit ͷొ৔ ͜Ε͕େ͖͍
  15. 37 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. • Y6OJUͷొ৔Ͱ

    • ඪ४Խ͞Εͨ࿮૊Έ͕Ͱ͖ͨ • ςετίʔυͱͯ͠؅ཧͰ͖ΔΑ͏ʹ • ςετ͸ࢿ࢈Ͱ͋Δͱ͍͏ߟ͑ํʹ xUnit ͷొ৔ ͜Ε͕େ͖͍ ςετࣗಈԽͷ࣌୅͕΍͖ͬͯͨ
  16. 39 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. • 5%%

    • ςετۦಈ։ൃ • ςετΛۦಈݯͱͯ͠։ൃ͢Δख๏ͷొ৔ • 3FEˠ(SFFOˠ3FGBDUPS • ྑ͍ઃܭͱ͸ςετ͠΍͍͢͜ͱͩ
 ͱ͍͏ݴ༿΋ੜ·Εͨ TDD ͷొ৔ 5FTU%SJWFO%FWFMPQNFOU
  17. 40 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. • 5%%

    • ςετۦಈ։ൃ • ςετΛۦಈݯͱͯ͠։ൃ͢Δख๏ͷొ৔ • 3FEˠ(SFFOˠ3FGBDUPS • ྑ͍ઃܭͱ͸ςετ͠΍͍͢͜ͱͩ
 ͱ͍͏ݴ༿΋ੜ·Εͨ TDD ͷొ৔ 5FTU%SJWFO%FWFMPQNFOU ςετ͕୯ͳΔಈ࡞֬ೝʹ ͱͲ·Βͳ͘ͳ͖ͬͯͨ
  18. 42 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. • #%%

    • 5%%͔Β೿ੜ • ৼΔ෣͍ۦಈ։ൃ • ཁٻ࢓༷ʹ͍ۙܗͰςετ͕هड़͞ΕΔ • J04Ͱ͸ʁ • 2VJDL/JNCMF͕༗໊ BDD ͷొ৔ #FIBWJPS%SJWFO%FWFMPQNFOU 3VCZͷ3TQFDͳͲʹΠϯεύΠΞ ର৅ͷৼΔ෣͍ʹ஫໨͢Δ
  19. 43 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. • #%%

    • 5%%͔Β೿ੜ • ৼΔ෣͍ۦಈ։ൃ • ཁٻ࢓༷ʹ͍ۙܗͰςετ͕هड़͞ΕΔ • J04Ͱ͸ʁ • 2VJDL/JNCMF͕༗໊ BDD ͷొ৔ #FIBWJPS%SJWFO%FWFMPQNFOU 3VCZͷ3TQFDͳͲʹΠϯεύΠΞ ର৅ͷৼΔ෣͍ʹ஫໨͢Δ ςεςΟϯάϑϨʔϜϫʔΫͷ ଟ༷Խ͕࢝·ͬͨɻ
  20. 45 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. • 6*ςετ

    • )551ϞοΩϯά • 1SPQFSUZCBTFE5FTUJOH • ΩϟϓνϟˍϦϓϨΠ • .POLFZ3VOOFSʢϥϯμϜૢ࡞Ͱམͪͳ͍͔ʣ ଞʹ΋͍Ζ͍Ζ
  21. 46 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. • 6*ςετ

    • )551ϞοΩϯά • 1SPQFSUZCBTFE5FTUJOH • ΩϟϓνϟˍϦϓϨΠ • .POLFZ3VOOFSʢϥϯμϜૢ࡞Ͱམͪͳ͍͔ʣ ଞʹ΋͍Ζ͍Ζ ୯७ͳΧςΰϥΠζ͚ͩͰ΋ ͔ͳΓͷྔͷϥΠϒϥϦɾFW͕
  22. 48 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. • ͳͥςετΛࣗಈԽ͢Δͷ͔ʁ

    • खಈςετʹ͓͚Δ՝୊ • ΦϨΦϨࣗಈςετʹ͓͚Δ՝୊ • Y6OJUͷొ৔ • 5%%ͷొ৔ • #%%ͷొ৔ • ςεςΟϯάϑϨʔϜϫʔΫɾϥΠϒϥϦͷଟ༷Խ ͜͜·Ͱ
  23. 49 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. • ͳͥςετΛࣗಈԽ͢Δͷ͔ʁ

    • खಈςετʹ͓͚Δ՝୊ • ΦϨΦϨࣗಈςετʹ͓͚Δ՝୊ • Y6OJUͷొ৔ • 5%%ͷొ৔ • #%%ͷొ৔ • ςεςΟϯάϑϨʔϜϫʔΫɾϥΠϒϥϦͷଟ༷Խ ͜͜·Ͱ ྺ࢙΍ܦҢΛཧղ͓͚ͯ͠͹ πʔϧɾϑϨʔϜϫʔΫʹ ৼΓճ͞ΕΔ͜ͱ΋ͳ͍ʢ͔΋ʣ
  24. 51 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. • 9$5"TTFSU&RVBM

    ݁Ռ ظ଴஋  • ੒ޭˠʮ྘ʯ • ࣦഊˠʮ੺ʯ Ξαʔγϣϯ ظ଴஋ͱಉ͔͡ϓϩάϥϜͰൺֱ 5%%ʹ͓͚Δʮ3FEʯʮ(SFFOʯͷޠݯ
  25. 59 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. XCTest ͷΞαʔγϣϯҰཡ

    ෼ྨ ௨ৗ ൱ఆܗʢNot / Noʣ ౳஋൑ఆ XCTAssertEqual XCTAssertNotEqual nil൑ఆ XCTAssertNil XCTAssertNotNil Bool൑ఆ XCTAssertTrue XCTAssertFalse > XCTAssertGreaterThan XCTAssertLessThan >= XCTAssertGreaterThanOrEqual XCTAssertLessThanOrEqual ྫ֎ XCTAssertThrowsError XCTAssertNoThrow ࣦഊͤ͞Δ XCTFail -
  26. 60 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. XCTest ͷΞαʔγϣϯҰཡ

    ෼ྨ ௨ৗ ൱ఆܗʢNot / Noʣ ౳஋൑ఆ XCTAssertEqual XCTAssertNotEqual nil൑ఆ XCTAssertNil XCTAssertNotNil Bool൑ఆ XCTAssertTrue XCTAssertFalse > XCTAssertGreaterThan XCTAssertLessThan >= XCTAssertGreaterThanOrEqual XCTAssertLessThanOrEqual ྫ֎ XCTAssertThrowsError XCTAssertNoThrow ࣦഊͤ͞Δ XCTFail - ͍͍ͩͨ൱ఆܗ͕͋Δ
  27. 61 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. XCTest ͷΞαʔγϣϯҰཡ

    ෼ྨ ௨ৗ ൱ఆܗʢNot / Noʣ ౳஋൑ఆ XCTAssertEqual XCTAssertNotEqual nil൑ఆ XCTAssertNil XCTAssertNotNil Bool൑ఆ XCTAssertTrue XCTAssertFalse > XCTAssertGreaterThan XCTAssertLessThan >= XCTAssertGreaterThanOrEqual XCTAssertLessThanOrEqual ྫ֎ XCTAssertThrowsError XCTAssertNoThrow ࣦഊͤ͞Δ XCTFail - ྫ֎ͷεϩʔͷςετ
  28. 62 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. XCTest ͷΞαʔγϣϯҰཡ

    ෼ྨ ௨ৗ ൱ఆܗʢNot / Noʣ ౳஋൑ఆ XCTAssertEqual XCTAssertNotEqual nil൑ఆ XCTAssertNil XCTAssertNotNil Bool൑ఆ XCTAssertTrue XCTAssertFalse > XCTAssertGreaterThan XCTAssertLessThan >= XCTAssertGreaterThanOrEqual XCTAssertLessThanOrEqual ྫ֎ XCTAssertThrowsError XCTAssertNoThrow ࣦഊͤ͞Δ XCTFail - ༧ظ͠ͳ͍෼ذʹೖͬͨͱ͖ͳͲ
  29. 64 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. • 9$5"TTFSUܥͷؔ਺ʹʮ೚ҙʯͰ༩͑ΒΕΔ

    • ࢦఆͨ͠৔߹͸ςετࣦഊ࣌ʹग़ྗ͞ΕΔ ࣦഊ࣌ͷΤϥʔϝοηʔδ
  30. 70 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. • શ෦ʹॻ͘΂͖ʁ

    • ৑௕ͳέʔε͕ଟ͍ • ໘౗ͩͱਓ͸ʮϛεʯ͠΍͘͢ͳΔ • όϥϯε͕ॏཁ • #%% • Ϛονϟʔ"1*ʹΑΓࣗવͳӳจͷΑ͏ͳίʔυʹ • ࣦഊ࣌ͷΤϥʔϝοηʔδ΋ࣗಈੜ੒ ࣦഊ࣌ͷΤϥʔϝοηʔδ ٯޮՌʹͳΔ͜ͱ΋
  31. 72 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. • 9$5FTU

    • Ξαʔγϣϯ͸جຊతͳ΋ͷ͚ͩ • ࣗ࡞͢ΔͱಡΈ΍͘͢ͳΔ͜ͱ΋ • 2VJDL/JNCMF • ૊ΈࠐΈͰศརͳϚονϟʔ͕༻ҙ • ྫʣ഑ྻͷதʹ೚ҙͷཁૉؚ͕·Ε͍ͯΔ͔ • FYQFDU BSSBZ UP DPOUBJO GPVS ಠࣗΞαʔγϣϯ
  32. 89 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. • 9$5FTU

    • TFU6QUFBS%PXOͰલޙॲཧ͕ߦ͑Δ • Ϋϥε୯ҐʢDMBTTNFUIPEʣ • ϝιου୯Ґ • 2VJDL/JNCMF • %4-ͱͯ͠ಠࣗͷ࢓૊Έ͕༻ҙ • CFGPSF&BDIBGUFS&BDIͳͲ લޙॲཧͷڞ௨Խ
  33. 97 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. • ςετΛ֊૚ԽʢάϧʔϐϯάʣͰ͖Δ

    • 9DPEF͔Β௥Ճ͞Εͨ • ςετͷΧςΰϥΠζͳͲʹศར • 2VJDL • %4-ʹΑΔݫ֨ͳߏ଄Խ • ཁٻ࢓༷Λهड़͢ΔΑ͏ͳΠϝʔδ XCTContext
  34. 103 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. • 1MBZHSPVOEʹΑΔΞαʔγϣϯ

    • ΞαʔγϣϯͷҰཡ • ࣦഊ࣌ͷΤϥʔϝοηʔδ • ಠࣗΞαʔγϣϯͷ࡞੒ • લޙॲཧͷڞ௨Խ • ςετͷ֊૚Խ XCTestʢ࠶ʣೖ໳
  35. 104 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. • 1MBZHSPVOEʹΑΔΞαʔγϣϯ

    • ΞαʔγϣϯͷҰཡ • ࣦഊ࣌ͷΤϥʔϝοηʔδ • ಠࣗΞαʔγϣϯͷ࡞੒ • લޙॲཧͷڞ௨Խ • ςετͷ֊૚Խ XCTestʢ࠶ʣೖ໳ ͍͍ײ͡ʹ࠶ೖ໳Ͱ͖ͨʁ ৽͍͠ൃݟ͕͋ͬͨͳΒ޾͍Ͱ͢
  36. 106 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. • ςετࣗಈԽ

    • ϓϩάϥϚ͸܁Γฦ͕͠໘౗ʢࣗಈԽ͢Δͷ͸ඞવʣ • ςεςΟϯά'8ʹΑΓࣗಈԽͷ࿮૊Έ͕ग़དྷͨ • 5%%#%%ͳͲͷ։ൃख๏΋஀ੜ • ϥΠϒϥϦͷଟ༷Խ ·ͱΊ ʮͳͥʁʯΛཧղ͢ΔͱৼΓճ͞Εͳ͍
  37. 107 Copyright (C) DeNA Co.,Ltd. All Rights Reserved. • 9$5FTUʢ࠶ʣೖ໳

    • ॳ৺ʹ໭ͬͯ࠶ೖ໳ͯ͠Έͨ • ෮शˍ஌ࣝͷମܥԽʹͭͳ͕ͬͯྑ͍ ·ͱΊ օ༷ͷൃද΋͓଴ͪͯ͠·͢ʂ