Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
20171002Testing
Search
Shigure Shimotori
October 02, 2017
Programming
2
1.7k
20171002Testing
#orecon_ios #ios_test_night
Shigure Shimotori
October 02, 2017
Tweet
Share
More Decks by Shigure Shimotori
See All by Shigure Shimotori
1人で挑むSwiftコンパイラ 〜型システム入門編〜
s_shimotori
0
400
英語
s_shimotori
1
380
Parallel Socket Communication in Swift
s_shimotori
1
610
UIColor Anatomy
s_shimotori
1
2.3k
UIColor Cluster
s_shimotori
1
660
iOSDC Japan 2019 60 mins for color
s_shimotori
5
3.7k
wwdc19
s_shimotori
2
320
SE-0246 Generic Math(s) Functions
s_shimotori
2
2.4k
Introduction to Font and Typesetting
s_shimotori
4
3.7k
Other Decks in Programming
See All in Programming
Removing Corepack
yosuke_furukawa
PRO
9
1.1k
AWS Lambda Web Adapterを活用する新しいサーバーレスの実装パターン
tmokmss
6
5.8k
dbt-ga4パッケージを実業務に導入してみた話
t_tokumaru_feedcorp
0
120
RDBの世界をぬりかえていくモデルグラフDB〜truncus graphによるモデルファースト開発〜
jurabi
0
160
推しの夫に恋のGPS「ときメーター」#M5Stack #IoT #M5JPTour2024
riyu
0
230
型付きで行うVSCode拡張機能開発 / VSCode Meetup #31
mazrean
0
230
学生の時に開催したPerl入学式をきっかけにエンジニアが組織に馴染むために勉強会を主催や仲間と参加して職能間の境界を越えていく
ohmori_yusuke
1
120
Vue :: Better Testing 2024
up1
1
380
Quarto Clean Theme
nicetak
0
220
Kotlin Multiplatform at Stable and Beyond (Kotlin Vienna, October 2024)
zsmb
2
340
sqlcを利用してsqlに型付けを
kamiyam
0
240
DevFest Android in Korea 2024 - 안드로이드의 문단속 : 앱을 지키는 암호화 이야기
mdb1217
1
140
Featured
See All Featured
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
504
140k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Building Adaptive Systems
keathley
37
2.1k
The Invisible Side of Design
smashingmag
297
50k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
38
2.1k
How GitHub (no longer) Works
holman
311
140k
How to name files
jennybc
77
99k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
92
16k
GraphQLとの向き合い方2022年版
quramy
43
13k
Gamification - CAS2011
davidbonilla
80
5k
Unsuck your backbone
ammeep
667
57k
A Tale of Four Properties
chriscoyier
155
22k
Transcript
Զίϯ Vol.1 / Day.1 (iOSDC Japan 2017 #1312) ࠓͦ͜ςετͷؾ࣋ͪΛߟ͑Δ @S_Shimotori
ͩΕ • @S_Shimotori / @S_Shimotori_pub • ৬ۀ: ֶੜ • GCςετઐͰͳ͍
• iOSDCͰʮARC vs. GCʁARC in GCʁʯΛΓ·ͨ͠ • ࠓiOS Test NightͰདྷ·ͨ͠
ษڧձΛΓา͍ͯͬͨ͜ͱ
ࣾձਓ ςετΛॻ͔ͳ͍ʂʂ
ͱ͍͏͔୭ςετΛॻ͔ͳ͍ • ࣾձਓςετΛॻ͔ͳ͍ • ͕࣌ؒͳ͍ • ͦΜͳ͜ͱΑΓͬ͞͞ͱϦϦʔε͠Α͏ͥʂ • ֶੜςετΛॻ͔ͳ͍(ࢲΛؚΉ) •
ͦͦςετͬͯԿͰ͔͢ʁ • ͦΕҎલʹΞϓϦ։ൃͬͯԿͰ͔͢ʁ • ςετͳΜ͔ॻ͍ͯͨΒ՝ఏग़ʹؒʹ߹Θͳ͍ ʘ(^o^)ʗ Φɹϫɹλ
ςετΛऔΓר͘ݱঢ় • ςετΛֶͿػձ͕ͳ͍ • ςετΛ࣮ફ͢Δػձ͕ͳ͍ • ςετηογϣϯޙͷ࠙ձͰఘΊͷݴ༿
ͱ͍͏Θ͚Ͱ
ຊηογϣϯͰѻ͏͜ͱ • ςετςετͬͯɼԿ͕ςετ͔Θ͔ͬͯΔͷʁ • ͖ͬͱςετ໘ന͍ͣͳΜͩ • ςετؔͰݸਓతʹ໘ന͍ͱࢥͬͨϙΠϯτ
ςετςετͬͯɼ Կ͕ςετ͔Θ͔ͬͯΔͷʁ
XCTest.framework͕ݴ͏ͱ͜Ζͷςετ • ςετυΩϡϝϯτͰΑ͘ఆ͕ٛޠΒΕΔ • XCTestͷ߹: assertion / ςετ݁Ռͷه / ύϑΥʔϚϯεͷଌఆ
/ UIૢ࡞[1] [1] https://developer.apple.com/documentation/xctest
͜ΕͰඞཁेʁ
ςετͱͦͦԿऀ͔ʁ(1/2) • ސ٬͕ཉ͍͠ͷΛ࡞Ε͔͔ͨ֬ΊΔख๏ͷ1ͭ • XCTestͷڍ͛ͨྫ͞Βʹͦͷதͷ΄ΜͷҰ෦ • ςετҎ֎ͷखஈͱͯ͠ϞσϧݕࠪͳͲ͕͋Δ ↓͍ͭͷΞϨ↓
ςετͱͦͦԿऀ͔ʁ(2/2) • ςετରͷܽؕΛ୳͢Ұ࿈ͷϓϩηε • ํܭըΛཱͯΔͱ͜Ζ͔Β࢝·͍ͬͯΔ • ձࣾશମͷํʁຊϓϩδΣΫτͰͷςετܭըʁ • ࣮ࡍʹϓϩάϥϜΛ࣮ߦ͢ΔͱݶΒͳ͍ •
ίʔυϨϏϡʔɹ ཱͩͬͯͳςετʂ • ͍Ζ͍Ζͳςετͷछྨɺ͚ํ͕͋Δ • ੩తɺಈత • ύϑΥʔϚϯεɺηΩϡϦςΟɺetc…
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͕શͯͰͳ͍ʂ
ͭ·Γʁ
Θ͔ͨ͠Βͷ͓ئ͍ • ςετΛͯ͠ͳ͍ਓͳͲ͍ͳ͍ʂ • ͋ͳͨͷྡͷ੮ͷਓ͖ͬͱᘳʹͬͯͳ͍Α • iOS Test Nightʹ͓͍ͯಉ͡ •
fastlaneᘳ͡Όͳ͍ͬͯgiginet͞Μ͕ݴͬͯͨ[4] • Կ͔औΓΉ͜ͱ͕Ͱ͖ͨΒڞ༗͍ͯͩ͘͠͞ • ݶΒΕͨਓ݄ͰطͷͷΛಋೖ͢Δ͜ͱݟͷ1ͭ [4] https://speakerdeck.com/giginet/fastlane-contributordakedohe-kazhi-wen-aru
࣍
͖ͬͱςετ໘ന͍ͣͳΜͩ
ςετʮ͜͏ॻ͍ͯ΄͍͠ʯͱࢥ͍ͬͯΔ͔ • ςετʹن͕֨͋Δ • XCTest͕Ͱ͖Δ͜ͱ • iOS༻ͷϥΠϒϥϦͷςετΛݟͯΈΔ • ͦͷ΄͔ɺԶ͕ؾʹͳΔςετɹུͯ͠……ͳΜͩΖ͏
ςετʹن͕֨͋Δ
ςετʹن͕֨͋Δ • 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
XCTest͕Ͱ͖Δ͜ͱ
XCTestʹ͋Δͷ • Test Cases and Test Methods • Test Assertions
• Asynchronous Tests • UI Tests • Activities and Attachments • Test Execution : XCTestͷجຊ෦ : Darwinಛ༗orޙ͚
xUnitੜ͔ΒXCTestʹࢸΔ·Ͱ • 1994ࠒʹK. Beck͕SUnitΛ࡞ͬͨͷ͕࢝·Γ • scripted testʹқ͍༷ͯͨ͠͝ࢠ • JUnitK. BeckΒ͕SUnitΛJavaʹҠ২ͨ͠ͷ
• Python unittestJUnitͷੜ • JUnit4ΞϊςʔγϣϯΛ࠾༻͢ΔͳͲมΘͬͨ ڭ͑ͯৄ͍͠ਓ • 2005ͨͿΜ ɺXcode2.1͕OCUnitΛ࠾༻ • Objective-C༻ͷϑϨʔϜϫʔΫ • 2013ɺXcode5.0͕XCTestΛ࠾༻
K. Beck͞ΜΦεεϝͷΓ͔ͨ • ΫϥεຖʹϢχοτςετΛॻ͖͘ • ৼΔ͍͕୯७ͳͷ͔Βઓ͍ͯ͜͠͏ • ౷߹ςετผͷਓ͕࣮͢Δ͖ • 25ʙ50%ͷ࣌ؒΛςετ։ൃʹ͏͖
xUnitʹ͓͚Δ࣮ύλʔϯ • Fixture • TestCasesetUpΛͬͯڞ௨ͷςετڥΛ༻ҙ • Test Case • ࣮ɺೖྗɺظ݁Ռͷू߹Λ༻ҙ
• ޓ͍ͷ݁ՌʹӨڹ͕ͳ͍ͷ͕ϛι • Check • ࣮݁Ռͱظ݁ՌΛൺֱ • ࣦഊͨ͠Β࣍ͷtest caseͷॲཧʹҠΔ • Test Suite • test caseͷू߹Λཧ͢Δ
XCTestͷಛ • ෳࡶͳܧঝؔʹ͋ΔΫϥε͕ఏڙ͞Ε͍ͯΔ • ࣗ༝ʹsetUp/tearDown͍ͤͨ͞ΜͰ͔͢Ͷʁ • ͪΖΜXCTestCase͚ͩͰςετՄೳ
ৄ͘͠WebͰ
XCTest͕ੜ·Ε͔ͯΒ • 2014ɺXcode6.0ʹύϑΥʔϚϯεςετͱ ඇಉظॲཧςετΛՃ • 2015ɺXcode7.0ʹUIςετՃ • Instruments UIAutomation͔ΒͷҠߦ •
2016ɺ • 2017ɺXcode8.3/9.0Ͱࡉ͔͍Ճͱमਖ਼
iOS༻ͷϥΠϒϥϦͷ ςετΛݟͯΈΔ
ྲྀߦΓͷϥΠϒϥϦΛݟͯΈΑ͏ʂ • ௐࠪର: ʮ2017Λࢧ͢ΔϥΠϒϥϦʯ[11]ଞ • UIϥΠϒϥϦͷςετ • εΫγϣͰݟ͔͑ͨΛ͔֬ΊΔ • ௨৴ςετ
• ϓϩδΣΫτͷςετํ • ςετίʔυࣗಈੜ • ͓·͚: SPM༻ͷॲஔ [11]https://medium.com/app-coder-io/33-ios-open-source-libraries-that-will-dominate-2017-4762cf3ce449
೦ͳ͓Βͤ • ਓؾͰظגͷϥΠϒϥϦ != ͔ͬ͠ΓςετࡁΈ • Δਓ͕͍ͳ͍͔Βʁςετ͢Δͷ͕͍͔͠Βʁ • 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
UIϥΠϒϥϦͷςετ • UIςετ͍ͯ͠ͳ͍͜ͱ͕ଟ͍ • ʮσʔλΛ༩͑ΔˠཁૉΛΞαʔγϣϯͰ֬ೝʯ͕ఆ൪ • ࣮ࡍͲ͏ݟ͑Δ͔Α͘Θ͔Βͳ͍ https://github.com/Instagram/IGListKit/blob/d9a89c9b00aa1a9537a24d9affb6919f83065f65/Tests/IGListAdapterE2ETests.m
εΫγϣͰݟ͔͑ͨΛ͔֬ΊΔ • ࣮ࡍͷݟͨ·ͰνΣοΫ͍ͯ͠Δ͜ͱ͋Δ • ݁ہਓྗͰࢹ • εΫγϣΛࡱΔํ๏3छ • facebook/ios-snapshot-test-case •
fastlane/fastlane/tree/master/snapshot • XCUIScreenshot https://github.com/danielgindi/Charts/blob/d300d6d332afa2e790fd616e5a8326e815b0e1f0/Tests/Charts/BarChartTests.swift
௨৴Λߦ͏ϥΠϒϥϦͷςετ • ௨৴ઌͲ͔͜Βௐୡͯ͘͠Δͷ͔ʁ • ελϒΛ༻͍Δ • ishkawa/APIKit • AliSoftware/OHHTTPStubs→ಠ࣮ࣗ •
ౖͬͯΒΕͳ͍αʔό • onevcat/Hedwig • ϩʔΧϧˠϥΠϒϥϦ։ൃऀͷϝʔϧαʔόʔ(ʁ) • Alamofire/Alamofire • httpbin(1)
ϓϩδΣΫτͷςετํ(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
ϓϩδΣΫτͷςετํ(ReactiveX/RxSwift) • ݩΛͨͲΕReactiveX • ݟ͔ͭΓ·ͤΜͰͨ͠… • ݟ͚ͭͨΒڭ͑ͯʂ
ςετίʔυࣗಈੜ • ςετίʔυΛࣗಈੜͯ͠खؒΛল͘ • ͦΕͧΕ͕ಠࣗʹੜϓϩάϥϜΛ࡞ͬͯΓ͘Γ͍ͯ͠Δ • Ҿ͕ҧ͏͚ͩͷϝιου͕ଟ͍࣌ʹʹཱͭ • ReactiveX/RxSwift •
ؔςετࣗಈੜ • thoughtbot/Curry • ؔΛࣗಈੜ(ςετͳ͠)
(͓·͚)SPM༻ͷॲஔ • AlamofireͳͲ • ύοέʔδ͔ΒςετΛ·Δ͝ͱআ֎ • RxSwiftͳͲ • exclude#if os(Linux)ΛͬͯCocoaΛִ
• APIKit • OHHTTPStub(SPMඇରԠ)͔ΒࣗલελϒʹΓ͑
·ͱΊ
·ͱΊ • ͬͱςετʹରͯ͠ϙδςΟϒʹ͍͖·ͤΜ͔ʁ • ݟΛڞ༗͍ͯͩ͘͠͞ʂ • ςετ͍Ζ͍ΖͳऔΓΈ͕͋ͬͯ໘ന͍ʂ • ࣗಈςετΛ͠ͳ͍ʹͯ͠ɺ͕ࣝ͋ͬͯଛ͠ͳ͍ •
ޙͰςετΛಋೖ͍͢͠ઃܭʹ͍ͨ͠Ͱ͢Ͷ
ͨͷ͍͠ࢀߟจݙ • 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)ɽ