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.8k
20171002Testing
#orecon_ios #ios_test_night
Shigure Shimotori
October 02, 2017
Tweet
Share
More Decks by Shigure Shimotori
See All by Shigure Shimotori
Synchronizationを支える技術
s_shimotori
1
160
1人で挑むSwiftコンパイラ 〜型システム入門編〜
s_shimotori
0
530
英語
s_shimotori
1
470
Parallel Socket Communication in Swift
s_shimotori
1
650
UIColor Anatomy
s_shimotori
1
2.3k
UIColor Cluster
s_shimotori
1
690
iOSDC Japan 2019 60 mins for color
s_shimotori
5
3.7k
wwdc19
s_shimotori
2
330
SE-0246 Generic Math(s) Functions
s_shimotori
2
2.4k
Other Decks in Programming
See All in Programming
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
150
Tauriでネイティブアプリを作りたい
tsucchinoko
0
370
エンジニアとして関わる要件と仕様(公開用)
murabayashi
0
300
Arm移行タイムアタック
qnighy
0
330
Jakarta EE meets AI
ivargrimstad
0
600
3rd party scriptでもReactを使いたい! Preact + Reactのハイブリッド開発
righttouch
PRO
1
610
Webの技術スタックで マルチプラットフォームアプリ開発を可能にするElixirDesktopの紹介
thehaigo
2
1k
Click-free releases & the making of a CLI app
oheyadam
2
120
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
480
cmp.Or に感動した
otakakot
3
200
WebフロントエンドにおけるGraphQL(あるいはバックエンドのAPI)との向き合い方 / #241106_plk_frontend
izumin5210
4
1.4k
NSOutlineView何もわからん:( 前編 / I Don't Understand About NSOutlineView :( Pt. 1
usagimaru
0
340
Featured
See All Featured
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
370
Writing Fast Ruby
sferik
627
61k
For a Future-Friendly Web
brad_frost
175
9.4k
Docker and Python
trallard
40
3.1k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Building an army of robots
kneath
302
43k
4 Signs Your Business is Dying
shpigford
180
21k
Statistics for Hackers
jakevdp
796
220k
The Invisible Side of Design
smashingmag
298
50k
Producing Creativity
orderedlist
PRO
341
39k
BBQ
matthewcrist
85
9.3k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
506
140k
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)ɽ