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
520
英語
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
as(型アサーション)を書く前にできること
marokanatani
10
2.6k
3rd party scriptでもReactを使いたい! Preact + Reactのハイブリッド開発
righttouch
PRO
1
600
シールドクラスをはじめよう / Getting Started with Sealed Classes
mackey0225
4
640
距離関数を極める! / SESSIONS 2024
gam0022
0
280
광고 소재 심사 과정에 AI를 도입하여 광고 서비스 생산성 향상시키기
kakao
PRO
0
170
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
100
見せてあげますよ、「本物のLaravel批判」ってやつを。
77web
7
7.7k
どうして僕の作ったクラスが手続き型と言われなきゃいけないんですか
akikogoto
1
120
GitHub Actionsのキャッシュと手を挙げることの大切さとそれに必要なこと
satoshi256kbyte
5
430
C++でシェーダを書く
fadis
6
4.1k
型付き API リクエストを実現するいくつかの手法とその選択 / Typed API Request
euxn23
8
2.2k
OnlineTestConf: Test Automation Friend or Foe
maaretp
0
110
Featured
See All Featured
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
840
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Raft: Consensus for Rubyists
vanstee
136
6.6k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
329
21k
Optimizing for Happiness
mojombo
376
70k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
720
Making Projects Easy
brettharned
115
5.9k
Site-Speed That Sticks
csswizardry
0
23
KATA
mclloyd
29
14k
Unsuck your backbone
ammeep
668
57k
Git: the NoSQL Database
bkeepers
PRO
427
64k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
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)ɽ