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
190
1人で挑むSwiftコンパイラ 〜型システム入門編〜
s_shimotori
0
680
英語
s_shimotori
1
600
Parallel Socket Communication in Swift
s_shimotori
1
700
UIColor Anatomy
s_shimotori
1
2.4k
UIColor Cluster
s_shimotori
1
710
iOSDC Japan 2019 60 mins for color
s_shimotori
5
3.7k
wwdc19
s_shimotori
2
350
SE-0246 Generic Math(s) Functions
s_shimotori
2
2.4k
Other Decks in Programming
See All in Programming
『改訂新版 良いコード/悪いコードで学ぶ設計入門』活用方法−爆速でスキルアップする!効果的な学習アプローチ / effective-learning-of-good-code
minodriven
28
4.2k
Azure AI Foundryのご紹介
qt_luigi
1
210
Lookerは可視化だけじゃない。UIコンポーネントもあるんだ!
ymd65536
1
130
HTML/CSS超絶浅い説明
yuki0329
0
190
watsonx.ai Dojo #6 継続的なAIアプリ開発と展開
oniak3ibm
PRO
0
170
ecspresso, ecschedule, lambroll を PipeCDプラグインとして動かしてみた (プロトタイプ) / Running ecspresso, ecschedule, and lambroll as PipeCD Plugins (prototype)
tkikuc
2
1.9k
PicoRubyと暮らす、シェアハウスハック
ryosk7
0
220
Scaling your build logic
antalmonori
1
100
EC2からECSへ 念願のコンテナ移行と巨大レガシーPHPアプリケーションの再構築
sumiyae
3
590
PHPカンファレンス 2024|共創を加速するための若手の技術挑戦
weddingpark
0
140
Package Traits
ikesyo
1
210
chibiccをCILに移植した結果 (NGK2025S版)
kekyo
PRO
0
130
Featured
See All Featured
Git: the NoSQL Database
bkeepers
PRO
427
64k
Building Adaptive Systems
keathley
38
2.4k
Testing 201, or: Great Expectations
jmmastey
41
7.2k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
27
1.5k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
3
180
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Learning to Love Humans: Emotional Interface Design
aarron
274
40k
Building a Scalable Design System with Sketch
lauravandoore
460
33k
Designing on Purpose - Digital PM Summit 2013
jponch
116
7.1k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
The Language of Interfaces
destraynor
155
24k
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)ɽ