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
What is iOSSnapshotTestCase
Search
Shingo Tamaki
August 24, 2018
Technology
1
890
What is iOSSnapshotTestCase
Description of how to use iOSSnapshotTestCase.
Shingo Tamaki
August 24, 2018
Tweet
Share
More Decks by Shingo Tamaki
See All by Shingo Tamaki
沖縄モバイルアプリ開発勉強会#1
tamaki
0
88
iOSアプリ開発を始めよう
tamaki
0
130
詳解xcresult.pdf
tamaki
0
310
メルペイでのリグレッションテスト自動化推進のこれまでとこれから
tamaki
0
690
What do you want to test with UI Test v2
tamaki
2
850
JPQRによって変わる日本のQRコード決済
tamaki
0
250
What's New in Testing
tamaki
1
58
What do you want to test with UI Test
tamaki
5
1.8k
How to control state in UI Test
tamaki
4
2.6k
Other Decks in Technology
See All in Technology
Postman と API セキュリティ / Postman and API Security
yokawasa
0
200
kargoの魅力について伝える
magisystem0408
0
200
Snowflake女子会#3 Snowpipeの良さを5分で語るよ
lana2548
0
220
生成AIのガバナンスの全体像と現実解
fnifni
1
180
Wantedly での Datadog 活用事例
bgpat
1
430
株式会社ログラス − エンジニア向け会社説明資料 / Loglass Comapany Deck for Engineer
loglass2019
3
31k
日本版とグローバル版のモバイルアプリ統合の開発の裏側と今後の展望
miichan
1
130
非機能品質を作り込むための実践アーキテクチャ
knih
3
870
宇宙ベンチャーにおける最近の情シス取り組みについて
axelmizu
0
110
Turing × atmaCup #18 - 1st Place Solution
hakubishin3
0
470
.NET 9 のパフォーマンス改善
nenonaninu
0
710
サービスでLLMを採用したばっかりに振り回され続けたこの一年のあれやこれや
segavvy
2
380
Featured
See All Featured
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.1k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Practical Orchestrator
shlominoach
186
10k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.9k
RailsConf 2023
tenderlove
29
940
Speed Design
sergeychernyshev
25
670
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
For a Future-Friendly Web
brad_frost
175
9.4k
VelocityConf: Rendering Performance Case Studies
addyosmani
326
24k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.5k
Imperfection Machines: The Place of Print at Facebook
scottboms
266
13k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
Transcript
iOSSnapshotTestCase ͰϏϡʔͷςετΛߦ͏
ࣗݾհ • ۄ৴ޛ • iOS Engineer • iOSDC2018Ͱελοϑ͠·͢
iOSSnapshotTestCaseͱ View based testingΛߦ͏ͨΊͷπʔϧ ݩFBSnapshotTestCaseͰɺͱͱFacebook Ϗϡʔͷը૾Λ͖߹ΘͤͯมߋҰக͢Δ͔Λςετ͢Δػೳ ͕͋Γ·͢ɻ
ḪΔࣄҰલ
ḪΔࣄҰલ
ผͷखஈΛݕ౼ͯ͠ΈͨΓ WiremockΛͬͨUIςετ https://speakerdeck.com/tamaki/wiremockdexing-uuitesuto
σϝϦοτ͋Γ·ͨ͠ • XCUITestͷ࣮ߦ࣌ؒ • XCUITestͰը໘ͷঢ়ଶΛ࡞Δखؒ
ͱࢥͬͨΒ...
iOSSnapshotTestCaseͱͯ͠෮׆ Uber͕Ҿ͖ܧ͙ܗͰ෮׆ https://github.com/uber/ios-snapshot-test-case
࠶ͼ͍࢝ΊΔࣄʹ͠·ͨ͠ɻ
iOSSnapshotTestCase ͷ͍ํ
Πϯετʔϧ target "Tests" do use_frameworks! pod 'iOSSnapshotTestCase' end
ઃఆ • FBREFERENCEIMAGEDIR: $(SOURCEROOT)/$ (PROJECT_NAME)Tests/ReferenceImages • IMAGEDIFFDIR: $(SOURCEROOT)/$(PROJECTNAME)Tests/ FailureDiffs
ςετ࡞ FBSnapshotTestCaseΛܧঝͨ͠ςετέʔεΛ࡞͠·͢ɻ class iOSSnapshotTestCaseSampleTests: FBSnapshotTestCase { }
ςετϝιου࡞ FBSnapshotVerifyViewͰରͷϏϡʔΛνΣοΫ͠·͢ɻ ରͷϏϡʔͷαΠζCGRect(x:y:width:height)ͳͲͰࢦఆ͠ ͓͖ͯ·͠ΐ͏ɻ view.frame = CGRect(x: 0, y: 0,
width: 768, height: 1024) FBSnapshotVerifyView(view, identifier: "view id")
ϦϑΝϨϯεը૾ͷ࡞ recordMode͕trueͷͰςετΛ࣮ߦ͢ΔͱϦϑΝϨϯε༻ը૾ ͕ੜ͞Ε·͢ɻ override func setUp() { super.setUp() recordMode =
true }
ϦϑΝϨϯεը૾ ReferenceImages_64ͷԼʹςετλʔήοτ໊.ςετέʔ ε໊ͷσΟϨΫτϦͱɺ ͦͷԼʹ͖߹ΘͤʹඞཁͱͳΔࢀর༻ը૾͕࡞͞Ε·͢ɻ iOSSnapshotTestCaseSampleTests/ ├── Info.plist ├── ReferenceImages_64 │
└── iOSSnapshotTestCaseSampleTests.TopScreenSnapshotTests │ └──
[email protected]
└── TopScreenSnapshotTests.swift
ϦϑΝϨϯεը૾
ςετͷ࣮ߦ recordModeΛfalseʹ͢ΔࣄΛΕͳ͍Α͏ʹɻ override func setUp() { super.setUp() recordMode = false
}
ςετ݁Ռ
ը໘͕มߋ͠ςετΛ࣮ߦ͢Δͱ... ૂ͍௨Γςετࣦഊ͠·ͨ͠Ͷʁ
FailureDiffsΛݟͯΈΑ͏ ├── FailureDiffs │ └── iOSSnapshotTestCaseSampleTests.TopScreenSnapshotTests │ ├──
[email protected]
│
├──
[email protected]
│ └──
[email protected]
├── Info.plist ├── ReferenceImages_64 │ └── iOSSnapshotTestCaseSampleTests.TopScreenSnapshotTests │ └──
[email protected]
└── TopScreenSnapshotTests.swift
FailureDiffsͷத FailureDiffsσΟϨΫτϦ͕ੜ͞Εɺ3ͭͷϑΝΠϧ͕ೖͬͯ· ͢ file name description diff_*.png Ϗϡʔͷ͖߹Θͤࠩ failed_*.png ݱࡏͷϏϡʔ
reference_*.png ࢀর༻ͷϏϡʔ(͋Δ͖Ϗϡʔͷը૾)
FailureDiffsͷத
ࢀর༻ͷը૾ͷ࠶ੜ ઌ΄ͲͷςετϏϡʔʹ͕ࠩ͋Γςετࣦഊ͠·ͨ͠ ͕ɺఆͨ͠௨Γͳ༁Ͱ͔͢Βɺ࠶ࢀর༻ͷը૾Λొ͠ ͠·͢ɻ
جຊతͳ͍ํ(·ͱΊ) ͜ͷΑ͏ͳ࡞ۀΛ܁Γฦ͢ࣄͰҎԼͷΑ͏ͳԸܙΛड͚Δ͜ͱ ͕Ͱ͖·͢ɻ • ҙਤ͠ͳ͍ը໘่ΕΛݕग़དྷΔ • PR࣌ʹϦϑΝϨϯεը૾ؚ͕·ΕΔࣄͰը໘ͷ֬ೝָ͕ʹͳ Δ
Tips
ෳαΠζͷରԠ ϏϡʔͷαΠζॎԣͷରԠͳͲͨ͘͠ͳΓ·͢ΑͶʁ ྫ͑ྻڍܕͰσόΠεαΠζΛఆٛ enum DeviceSize: String { case size_10_5_inch =
"10.5inch" case size_12_9_inch = "12.9inch" static func all() -> [DeviceSize] { return [ .size_10_5_inch, .size_12_9_inch, ] }
ෳαΠζͷରԠ ͖ຖͷ֤σόΠεͷαΠζ(Rect)Λฦ͢ϝιουΛੜͨ͠Γ ͢ΔͱָʹͳΓͦ͏Ͱ͢ɻ func frame(with orientation: UIInterfaceOrientation) -> CGRect {
switch (self, orientation) { case (.size_10_5_inch, .portrait): return CGRect(x: 0, y: 0, width: 834, height: 1112) case (.size_10_5_inch, .landscapeLeft): return CGRect(x: 0, y: 0, width: 1112, height: 834) case (.size_12_9_inch, .portrait): return CGRect(x: 0, y: 0, width: 1024, height: 1366) case (.size_12_9_inch, .landscapeLeft): return CGRect(x: 0, y: 0, width: 1366, height: 1024) default: return CGRect.zero } } }
ෳαΠζͷରԠ FBSnapshotVerifyViewجຊతʹ1ϏϡʔͣͭVerify͍ͯ͘͠ͷ Ͱ͕͢ɺSnapshotVerifyViewAllSizeΛ࡞ͬͯෳαΠζΛҰ ؾʹςετग़དྷΔΑ͏ʹͨ͠Γ͍ͯ͠·͢ɻ extension FBSnapshotTestCase { public func SnapshotVerifyViewAllSize(_
vc: UIViewController, identifier: String = "", orientation: UIInterfaceOrientation) { for size in DeviceSize.all() { XCTContext.runActivity(named: "\(identifier)_\(size.rawValue)", block: { activity in let view = vc.view! view.frame = size.frame(with: orientation) FBSnapshotVerifyView(view, identifier: activity.name) }) } } }
Ϗϡʔͷঢ়ଶ࡞Γʹ͍ͭͯ • XCUIDevice.shared.orientationΛsetupͰ੍ޚग़དྷΔʁ • ࣦഊ͢Δ͜ͱ͕͋ͬͨ(or ग़དྷͳ͔ͬͨ) هԱʹͳ ͍ •
࣮ߦΓ͘ͳͬͨ • UIςετͷΈΛ͏ࣄʹҧײΛײͨ͡ • ૉʹΠχγϟϥΠβͰDI͢Δࣄʹͨ͠
ɹϨϏϡʔ࣌ʹཱͭ GithubGitlabը૾ࠩΛදࣔͰ͖ΔΑ͏ʹͳͬͨͷͰϨ Ϗϡʔ࣌ʹԿ͕มΘ͔ͬͨΛ֬ೝ͍͢͠
ݒ೦ • ը໘͕ଟ͍ΞϓϦͷ߹ͷϦϙδτϦͷαΠζ૿Ճ • Uber͕ϝϯςΊΔ • ࠓࣗͰר͖औͬͯϝϯς͢Δؾ࣋ͪΛ࣋ͱ͏͔ͳ ͱɻ
·ͱΊ • UIςετE2EͰͳ͘ϏϡʔͷΈΛςετ͍ͨ͠߹ʹ͓ ͢͢ΊͰ͢ • ௨ৗͷ୯ମςετΑΓ͔͔࣌ؒΓ·͢ • ϏϡʔͷϓϩύςΟͳͲʹΞΫηεͯ͠ςετ͢Δํ๏ ͋Δ
Ҏ্ɺ͝੩ௌ͋Γ͕ͱ͏ ͍͟͝·ͨ͠ɻ
ࢀߟ https://github.com/facebookarchive/ios-snapshot-test-case https://github.com/facebookarchive/ios-snapshot-test-case/ issues/227#issuecomment-335175385 https://www.objc.io/issues/15-testing/snapshot-testing/