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

20171002Testing

 20171002Testing

#orecon_ios #ios_test_night

Bf65cc9bdf26321a7579ddca7930cd10?s=128

Shigure Shimotori

October 02, 2017
Tweet

Transcript

  1. Զίϯ Vol.1 / Day.1 (iOSDC Japan 2017 #1312) ࠓͦ͜ςετͷؾ࣋ͪΛߟ͑Δ @S_Shimotori

  2. ͩΕ • @S_Shimotori / @S_Shimotori_pub • ৬ۀ: ֶੜ • GC΋ςετ΋ઐ໳Ͱ͸ͳ͍

    • iOSDCͰʮARC vs. GCʁARC in GCʁʯΛ΍Γ·ͨ͠ • ࠓ೔͸iOS Test Night࿮Ͱདྷ·ͨ͠
  3. ษڧձΛ౉Γา͍ͯ஌ͬͨ͜ͱ

  4. ࣾձਓ͸ ςετΛॻ͔ͳ͍ʂʂ

  5. ͱ͍͏͔୭΋ςετΛॻ͔ͳ͍ • ࣾձਓ͸ςετΛॻ͔ͳ͍ • ͕࣌ؒͳ͍ • ͦΜͳ͜ͱΑΓͬ͞͞ͱϦϦʔε͠Α͏ͥʂ • ֶੜ΋ςετΛॻ͔ͳ͍(ࢲΛؚΉ) •

    ͦ΋ͦ΋ςετͬͯԿͰ͔͢ʁ • ͦΕҎલʹΞϓϦ։ൃͬͯԿͰ͔͢ʁ • ςετͳΜ͔ॻ͍ͯͨΒ՝୊ఏग़ʹؒʹ߹Θͳ͍ ʘ(^o^)ʗ Φɹϫɹλ
  6. ςετΛऔΓר͘ݱঢ় • ςετΛֶͿػձ͕ͳ͍ • ςετΛ࣮ફ͢Δػձ͕ͳ͍ • ςετηογϣϯޙͷ࠙਌ձͰఘΊͷݴ༿

  7. ͱ͍͏Θ͚Ͱ

  8. ຊηογϣϯͰѻ͏͜ͱ • ςετςετͬͯɼԿ͕ςετ͔Θ͔ͬͯΔͷʁ • ͖ͬͱςετ΋໘ന͍͸ͣͳΜͩ • ςετؔ܎Ͱݸਓతʹ໘ന͍ͱࢥͬͨϙΠϯτ

  9. ςετςετͬͯɼ Կ͕ςετ͔Θ͔ͬͯΔͷʁ

  10. XCTest.framework͕ݴ͏ͱ͜Ζͷςετ • ςετυΩϡϝϯτͰ͸Α͘ఆ͕ٛޠΒΕΔ • XCTestͷ৔߹:
 assertion / ςετ݁Ռͷه࿥ / ύϑΥʔϚϯεͷଌఆ

    / UIૢ࡞[1] [1] https://developer.apple.com/documentation/xctest
  11. ͜ΕͰඞཁे෼ʁ

  12. ςετͱ͸ͦ΋ͦ΋Կऀ͔ʁ(1/2) • ސ٬͕ཉ͍͠΋ͷΛ࡞Ε͔͔ͨ֬ΊΔख๏ͷ1ͭ • XCTestͷڍ͛ͨྫ͸͞Βʹͦͷதͷ΄ΜͷҰ෦ • ςετҎ֎ͷखஈͱͯ͠͸ϞσϧݕࠪͳͲ͕͋Δ ↓͍ͭ΋ͷΞϨ↓

  13. ςετͱ͸ͦ΋ͦ΋Կऀ͔ʁ(2/2) • ςετର৅ͷܽؕΛ୳͢Ұ࿈ͷϓϩηε • ํ਑΍ܭըΛཱͯΔͱ͜Ζ͔Β࢝·͍ͬͯΔ • ձࣾશମͷํ਑͸ʁຊϓϩδΣΫτͰͷςετܭը͸ʁ • ࣮ࡍʹϓϩάϥϜΛ࣮ߦ͢Δͱ͸ݶΒͳ͍ •

    ίʔυϨϏϡʔɹ ཱͩͬͯ೿ͳςετʂ • ͍Ζ͍Ζͳςετͷछྨɺ෼͚ํ͕͋Δ • ੩తɺಈత • ύϑΥʔϚϯεɺηΩϡϦςΟɺetc…
  14. Apple͕ݴ͏ͱ͜Ζͷςετ • Testing with Xcode[2] • Xcodeͷ࢖͍ํ΍XCTest.frameworkͷ࿩ • ςετ͠΍͍͢ίʔυͱ͸Կ͔ʹ͍ͭͯ΋ड़΂ΒΕ͍ͯΔ •

    App Testing Guide[3] • ςετͷखॱ΍ΞϓϦʹෆ۩߹Λى͜͢ओͳݪҼҰཡͳͲ • ؔ࿈͢ΔଞͷΨΠυ΁ͷϦϯΫ͕๛෋ [2] https://developer.apple.com/library/content/documentation/DeveloperTools/Conceptual/testing_with_xcode/ [3] https://developer.apple.com/library/content/technotes/tn2431/_index.html XCTest.framework͕શͯͰ͸ͳ͍ʂ
  15. ͭ·Γʁ

  16. Θ͔ͨ͠Βͷ͓ئ͍ • ςετΛͯ͠ͳ͍ਓͳͲ͍ͳ͍ʂ • ͋ͳͨͷྡͷ੮ͷਓ΋͖ͬͱ׬ᘳʹ͸΍ͬͯͳ͍Α • iOS Test Nightʹ͓͍ͯ΋ಉ͡ •

    fastlane΋׬ᘳ͡Όͳ͍ͬͯgiginet͞Μ͕ݴͬͯͨ[4] • Կ͔औΓ૊Ή͜ͱ͕Ͱ͖ͨΒڞ༗͍ͯͩ͘͠͞ • ݶΒΕͨਓ݄Ͱط஌ͷ΋ͷΛಋೖ͢Δ͜ͱ΋஌ݟͷ1ͭ [4] https://speakerdeck.com/giginet/fastlane-contributordakedohe-kazhi-wen-aru
  17. ͖ͬͱςετ΋໘ന͍͸ͣͳΜͩ

  18. ςετ͸ʮ͜͏ॻ͍ͯ΄͍͠ʯͱࢥ͍ͬͯΔ͔΋ • ςετʹ΋ن͕֨͋Δ • XCTest͕Ͱ͖Δ͜ͱ • iOS༻ͷϥΠϒϥϦͷςετΛݟͯΈΔ • ͦͷ΄͔ɺԶ͕ؾʹͳΔςετɹུͯ͠……ͳΜͩΖ͏

  19. ςετʹ΋ن͕֨͋Δ

  20. ςετʹ΋ن͕֨͋Δ • ISO/IEC/IEEE 29119[5][6][7][8][9] • ιϑτ΢ΣΞςετͷࠃࡍج४Λఆٛͨ͠γϦʔζ5ຊͩͯ • ਤ͕ڵຯਂ͍ • ମ੍੔උͷ͖ͨͨ୆ɺ༻ޠूͱͯ͠࢖͑Δ…͔΋

    • ISO/IEC TR 19759:2015[10] • ιϑτ΢ΣΞશൠ • ଏʹSWEBOK • ֶߍ͕ISO/IECऔͬͯͳ͍ΜͰ͢୭͔ങͬͯ͋ͱC++΋ཉ͍͠(?) [5]http://ieeexplore.ieee.org/document/6588537/ [6]http://ieeexplore.ieee.org/document/6588543/ [7]http://ieeexplore.ieee.org/document/6588540/ [8]http://ieeexplore.ieee.org/document/7346375/ [9]http://ieeexplore.ieee.org/document/7750539/ [10]https://www.iso.org/standard/67604.html
  21. XCTest͕Ͱ͖Δ͜ͱ

  22. XCTestʹ͋Δ΋ͷ • Test Cases and Test Methods • Test Assertions

    • Asynchronous Tests • UI Tests • Activities and Attachments • Test Execution : XCTestͷجຊ෦෼ : Darwinಛ༗orޙ෇͚
  23. xUnit஀ੜ͔ΒXCTestʹࢸΔ·Ͱ • 1994೥ࠒʹK. Beck͕SUnitΛ࡞ͬͨͷ͕࢝·Γ • scripted testʹ᫣қ͍༷ͯͨ͠͝ࢠ • JUnit͸K. BeckΒ͕SUnitΛJavaʹҠ২ͨ͠΋ͷ

    • Python unittest͸JUnitͷ೿ੜ • JUnit4͸ΞϊςʔγϣϯΛ࠾༻͢ΔͳͲมΘͬͨ ڭ͑ͯৄ͍͠ਓ • 2005೥ͨͿΜ ɺXcode2.1͕OCUnitΛ࠾༻ • Objective-C༻ͷϑϨʔϜϫʔΫ • 2013೥ɺXcode5.0͕XCTestΛ࠾༻
  24. K. Beck͞ΜΦεεϝͷ΍Γ͔ͨ • ΫϥεຖʹϢχοτςετΛॻ͘΂͖ • ৼΔ෣͍͕୯७ͳ΋ͷ͔Β௅ઓ͍ͯ͜͠͏ • ౷߹ςετ͸ผͷਓ͕࣮૷͢Δ΂͖ • 25ʙ50%ͷ࣌ؒΛςετ։ൃʹ࢖͏΂͖

  25. xUnitʹ͓͚Δ࣮૷ύλʔϯ • Fixture • TestCase΍setUpΛ࢖ͬͯڞ௨ͷςετ؀ڥΛ༻ҙ • Test Case • ࣮૷ɺೖྗɺظ଴݁Ռͷू߹Λ༻ҙ

    • ޓ͍ͷ݁ՌʹӨڹ͕ͳ͍ͷ͕ϛι • Check • ࣮݁Ռͱظ଴݁ՌΛൺֱ • ࣦഊͨ͠Β࣍ͷtest caseͷॲཧʹҠΔ • Test Suite • test caseͷू߹Λ؅ཧ͢Δ
  26. XCTestͷಛ௃ • ෳࡶͳܧঝؔ܎ʹ͋ΔΫϥε͕ఏڙ͞Ε͍ͯΔ • ࣗ༝ʹsetUp/tearDown͍ͤͨ͞ΜͰ͔͢Ͷʁ • ΋ͪΖΜXCTestCase͚ͩͰ΋ςετՄೳ

  27. ৄ͘͠͸WebͰ

  28. XCTest͕ੜ·Ε͔ͯΒ • 2014೥ɺXcode6.0ʹύϑΥʔϚϯεςετͱ
 ඇಉظॲཧςετΛ௥Ճ • 2015೥ɺXcode7.0ʹUIςετ௥Ճ • Instruments UIAutomation͔ΒͷҠߦ •

    2016೥ɺ௜໧ • 2017೥ɺXcode8.3/9.0Ͱࡉ͔͍௥Ճͱमਖ਼
  29. iOS༻ͷϥΠϒϥϦͷ ςετΛݟͯΈΔ

  30. ྲྀߦΓͷϥΠϒϥϦΛݟͯΈΑ͏ʂ • ௐࠪର৅: ʮ2017೥Λࢧ഑͢ΔϥΠϒϥϦʯ[11]ଞ • UIϥΠϒϥϦͷςετ • εΫγϣͰݟ͔͑ͨΛ͔֬ΊΔ • ௨৴ςετ

    • ϓϩδΣΫτͷςετํ਑ • ςετίʔυࣗಈੜ੒ • ͓·͚: SPM༻ͷॲஔ [11]https://medium.com/app-coder-io/33-ios-open-source-libraries-that-will-dominate-2017-4762cf3ce449
  31. ࢒೦ͳ͓஌Βͤ • ਓؾͰظ଴גͷϥΠϒϥϦ != ͔ͬ͠ΓςετࡁΈ • ΍Δਓ͕͍ͳ͍͔Βʁςετ͢Δͷ͕೉͍͔͠Βʁ • ObjC൛Ͱςετͯ͠Swift൛Ͱςετͯ͠ͳ͍ྫ΋͋Δ •

    όάͳ͠Ͱಈ࡞͢Δอূ͸ͳ͍ • UI͕ਓؒͷ໨ʹݟ͑Δܗʹͳ͍ͬͯΔ͔Ͳ͏͔΋ಉ༷ • ࣮ࡍʹಈ͔ͯ͠Έͳ͍͜ͱʹ͸Θ͔Βͳ͍ https://github.com/nickoneill/PermissionScope https://github.com/ViccAlexander/Chameleon https://github.com/krzyzanowskim/Natalie https://github.com/dani-gavrilov/GDPerformanceView-Swift
  32. UIϥΠϒϥϦͷςετ • UIςετ͸͍ͯ͠ͳ͍͜ͱ͕ଟ͍ • ʮσʔλΛ༩͑Δˠཁૉ਺ΛΞαʔγϣϯͰ֬ೝʯ͕ఆ൪ • ࣮ࡍͲ͏ݟ͑Δ͔͸Α͘Θ͔Βͳ͍ https://github.com/Instagram/IGListKit/blob/d9a89c9b00aa1a9537a24d9affb6919f83065f65/Tests/IGListAdapterE2ETests.m

  33. εΫγϣͰݟ͔͑ͨΛ͔֬ΊΔ • ࣮ࡍͷݟͨ໨·ͰνΣοΫ͍ͯ͠Δ͜ͱ΋͋Δ • ݁ہਓྗͰ໨ࢹ • εΫγϣΛࡱΔํ๏͸3छ • facebook/ios-snapshot-test-case •

    fastlane/fastlane/tree/master/snapshot • XCUIScreenshot https://github.com/danielgindi/Charts/blob/d300d6d332afa2e790fd616e5a8326e815b0e1f0/Tests/Charts/BarChartTests.swift
  34. ௨৴Λߦ͏ϥΠϒϥϦͷςετ • ௨৴ઌ͸Ͳ͔͜Βௐୡͯ͘͠Δͷ͔ʁ • ελϒΛ༻͍Δ • ishkawa/APIKit • AliSoftware/OHHTTPStubs→ಠ࣮ࣗ૷ •

    ࢖ͬͯ΋ౖΒΕͳ͍αʔό • onevcat/Hedwig • ϩʔΧϧˠϥΠϒϥϦ։ൃऀͷϝʔϧαʔόʔ(ʁ) • Alamofire/Alamofire • httpbin(1)
  35. ϓϩδΣΫτͷςετํ਑(mxcl/PromiseKit) • ݩΛͨͲΕ͹Promises/A+ • ཁ͔݅Βςετ·Ͱ༻ҙ͞Ε͍ͯΔ • ςετʹ߹֨͢Ε͹Promises/A+ͷϩΰΛܝࣔͰ͖Δ • ͜ΕͧBDD •

    PromiseKitͰ͸਌ϓϩδΣΫτ४ڌͷςετͱ
 ಠࣗͷςετͷ྆ํΛ͓͜ͳ͍ͬͯΔ • ࣗલͷdescribeϝιουΛۦ࢖ https://github.com/mxcl/PromiseKit/tree/master/Tests/A%2B https://github.com/promises-aplus/promises-tests/tree/master/lib/tests
  36. ϓϩδΣΫτͷςετํ਑(ReactiveX/RxSwift) • ݩΛͨͲΕ͹ReactiveX • ݟ͔ͭΓ·ͤΜͰͨ͠… • ݟ͚ͭͨΒڭ͑ͯʂ

  37. ςετίʔυࣗಈੜ੒ • ςετίʔυΛࣗಈੜ੒ͯ͠खؒΛল͘ • ͦΕͧΕ͕ಠࣗʹੜ੒ϓϩάϥϜΛ࡞ͬͯ΍Γ͘Γ͍ͯ͠Δ • Ҿ਺͕ҧ͏͚ͩͷϝιου͕ଟ͍࣌ʹ໾ʹཱͭ • ReactiveX/RxSwift •

    ؔ਺΋ςετ΋ࣗಈੜ੒ • thoughtbot/Curry • ؔ਺Λࣗಈੜ੒(ςετͳ͠)
  38. (͓·͚)SPM༻ͷॲஔ • AlamofireͳͲ • ύοέʔδ͔ΒςετΛ·Δ͝ͱআ֎ • RxSwiftͳͲ • exclude΍#if os(Linux)Λ࢖ͬͯCocoa෼Λִ཭

    • APIKit • OHHTTPStub(SPMඇରԠ)͔Βࣗલελϒʹ৐Γ׵͑
  39. ·ͱΊ

  40. ·ͱΊ • ΋ͬͱςετʹରͯ͠ϙδςΟϒʹ͍͖·ͤΜ͔ʁ • ஌ݟΛڞ༗͍ͯͩ͘͠͞ʂ • ςετ͸͍Ζ͍ΖͳऔΓ૊Έ͕͋ͬͯ໘ന͍ʂ • ࣗಈςετΛ͠ͳ͍ʹͯ͠΋ɺ஌͕ࣝ͋ͬͯଛ͸͠ͳ͍ •

    ޙͰςετΛಋೖ͠΍͍͢ઃܭʹ͸͍ͨ͠Ͱ͢Ͷ
  41. ͨͷ͍͠ࢀߟจݙ • Kent BeckʰBeck Testing Frameworkʱ<https://web.archive.org/web/20150315073817/http://www.xprogramming.com/ testfram.htm>ɼ(ࢀর2017-9-27) • Apple Inc.ʰXcode

    Release Notesʱ<https://developer.apple.com/library/content/releasenotes/DeveloperTools/RN-Xcode/>ɼ(ࢀ র2017-9-27) • Python Software Foundationʰ26.4. unittest — ϢχοτςετϑϨʔϜϫʔΫ — Python 3.6.1 υΩϡϝϯτʱ<https://docs.python.jp/ 3/library/unittest.html>ɼ(ࢀর2017-9-27) • খḺ૯߹σβΠϯࣄ຿ہʰʲ঎༻OKʳອը෩ϑϦʔૉࡐʮूதઢʯฤ 28ݸʲPNGɾAiʢIllustratorʣʳ | খḺ૯߹σβΠϯࣄ຿ہʛ ϗʔϜϖʔδ੍࡞ɾσβΠϯɾLINEελϯϓ੍࡞ʱ<http://otarunet.com/it/webdesign/comic-material-effect01/>ɼ(ࢀর2017-9- 18)ɽ