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
ユニットテストを学んだ次に知りたかったApple標準APIに対するテストのやり方
Search
ojun
June 04, 2023
Programming
480
1
Share
ユニットテストを学んだ次に知りたかったApple標準APIに対するテストのやり方
ojun
June 04, 2023
More Decks by ojun
See All by ojun
配列と所有権
ojun9
0
51
生成 AI 時代のスナップショットテストってやつを見せてあげますよ(α版)
ojun9
0
360
アセットのコンパイルについて
ojun9
0
220
Exit 8 for SwiftUI
ojun9
1
280
Swift Evolution かるた
ojun9
2
140
Xcode 16のPreviewModifierと@Previewableを活用した効率的なプレビュー方法の考察
ojun9
4
1k
Catch Up with Swift 5.10
ojun9
2
910
Overview: Swift OpenAPI Generator
ojun9
3
2.6k
if 式と switch 式による SwiftUI のプレビューエラー対策
ojun9
1
2.2k
Other Decks in Programming
See All in Programming
Kingdom of the Machine
yui_knk
2
1.4k
PHPでローカル環境用のSSL/TLS証明書を発行することはできるのか? #phpconkagawa
akase244
0
310
書籍「ユーザーストーリーマッピング」が私のバイブル
asumikam
4
470
ふりがな Deep Dive try! Swift Tokyo 2026
watura
0
270
mruby on C#: From VM Implementation to Game Scripting (RubyKaigi 2026)
hadashia
2
1.5k
[RubyKaigi 2026] Require Hooks
palkan
1
280
Making the RBS Parser Faster
soutaro
0
660
PHPでバイナリをパースして理解するASN.1
muno92
PRO
0
390
Structured Concurrency, Scoped Values and Joiners in the JDK 25 26 27
josepaumard
1
140
なぜあなたのコードには「コシ」がないのか?〜AI時代に問う、最後まで美味しい設計と戦略〜 #phpconkagawa / phpconkagawa2026
shogogg
0
110
リセットCSSを1行消したらアクセシビリティが向上した話
pvcresin
4
450
Firefoxにコントリビューションして得られた学び
ken7253
2
150
Featured
See All Featured
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
330
Agile that works and the tools we love
rasmusluckow
331
21k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
540
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.7k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
3k
The agentic SEO stack - context over prompts
schlessera
0
770
Being A Developer After 40
akosma
91
590k
What's in a price? How to price your products and services
michaelherold
247
13k
Prompt Engineering for Job Search
mfonobong
0
290
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.1k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
290
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
250
Transcript
ojun ϢχοτςετΛֶΜͩ࣍ʹ Γ͔ͨͬͨ Appleඪ४APIʹ ର͢ΔςετͷΓํ
ࣗݾհ • ໊લ • ojunʢ͓͡ΎΜʣ • ॴଐ • pixivࣄۀຊ෦ΞϓϦΤϯδχΞϦϯά •
࠷ۙ·͍ͬͯΔ͜ͱ • αʔϞϯϥϯ
ࠓճͷൃදʹ͍ͭͯ
ࠓճͷൃදʹ͍ͭͯ • Appleඪ४APIʹରͯ͠ϢχοτςετΛՃ͠Α͏ͱͯ͠ϋϚͬͨ͜ͱ ͱɺͦͷղܾํ๏Λɺ؆୯ͳσϞΞϓϦΛ௨ͯ͠ൃද͠·͢ • ಛʹࠓճҎԼͷΦϒδΣΫτʹରͯ͠ςετΛՃͨ͠Λ͠·͢ • UNUserNoti fi cationCenter
ର
ର • Ϣχοτςετͷॻ͖ํΛֶͼ࢝Ίͨਓ • ΞʔΩςΫνϟʔΛֶͼ࢝Ίͨਓ
σϞΞϓϦ֓ཁ
σϞΞϓϦ֓ཁ • 11ճ௨͕དྷΔϦϚΠϯυΞϓϦ • ෳͷλεΫ͕ొͰ͖Δ • ొͨ͠λΠϛϯά͔Β24 * n࣌ؒޙʹϩʔΧϧ௨͕དྷΔ •
λεΫΛআͰ͖Δ
σϞΞϓϦ֓ཁ
σϞΞϓϦ֓ཁ
σϞΞϓϦ֓ཁ
σϞΞϓϦ֓ཁ
σϞΞϓϦ֓ཁ • ϩʔΧϧ௨Λද͢ߏମΛఆٛ • ߏମʹҎԼͷ3͕ͭଘࡏ • ID • λΠτϧจݴ •
ϘσΟͷจݴ
σϞΞϓϦ֓ཁ • ొͨ͠ใUserDefaultsͰอଘ • Ճ͞ΕͨλΠϛϯάͰ UNUserNoti fi cationCenterʹՃ •
ͪͳΈʹ UNUserNoti fi cationCenterͷpendingRequest Λ͏Α͏ʹ͢ΕUserDefaultsʹอଘ͢Δඞཁ ͳ͘ͳΔ
Schedulerͷৄࡉ
Schedulerͷৄࡉ
Schedulerͷৄࡉ
Schedulerͷৄࡉ
লུ
লུ
Schedulerͷৄࡉ
Schedulerͷৄࡉ
Schedulerͷৄࡉ
Schedulerͷৄࡉ
Schedulerͷৄࡉ
• SchedulerΛੜͨ͠ޙʹҙͷϝιουΛݺͼग़͢ • ҾʹҙͷLocalNoti fi cationΛՃ͢Δ Schedulerͷ͍ํ
σϞΞϓϦͷ࣮ߦ
σϞΞϓϦͷ࣮ߦ • ӈ্ͷʮ+ʯϘλϯ͔ΒλεΫΛՃ͢Δ • Ճͨ͠λεΫ͕ͳ͘දࣔ͞ΕΔ • λεΫΛՃͨ͠ޙͷdebugදࣔ࣍ͷΑ͏ʹͳΔ
• ͳ͘௨ͷpending͕Ͱ͖͍ͯΔʂ🎉 λεΫΛՃͨ࣌͠ͷdebugදࣔ
ςετՃ͢Δͧʂ
Ճ͢Δςετͷ༰
• ඞཁͳ߲Λclass֎ʹఆٛ ςετ֓ཁ
• ඞཁͳ߲Λclass֎ʹఆٛ • localNoti fi cationΛมͱͯ͠ ఆٛ ςετ֓ཁ
• ҎԼͷςετΛॻ͘߹ɺpendig͞ΕͨϩʔΧϧ௨ΛऔΓग़͢͜ͱ͕ Ͱ͖ͳ͍ˠSchedulerΛमਖ਼ طଘͷModelͷ
লུ
লུ
লུ
• setLocalNoti fi cationΛՃͯ͠ϩʔΧϧ௨Λొ ʢ༰: ຖΔ͜ͱ / Ոʹண͍ͨΒ͓ṟΛग़͢ ʣ
ςετΛՃ͢Δ
• ͖ͬ͞मਖ਼ͨ͠มΛར༻ͯ͠pending͞Εͨ௨ΛऔΓग़͠ςετ͢ Δ ςετΛՃ͢Δ
• ඇಉظͷςετͳͷͰexpectionΛઃఆ͢Δ ςετΛՃ͢Δ
• AssertEqualͷޙʹful fi ll()͢Δ ςετΛՃ͢Δ
• ςετΛ࣮ߦ͢Δͱޭ͢Δ🎉 ςετΛՃ͢Δ
࣮ػͰΞϓϦΛىಈ͢Δͱɾɾɾ
࣮ػͰΞϓϦΛىಈ͢Δͱɾɾɾ
Կ͕ͩͬͨͷ͔ʁ
Կ͕ͩͬͨͷ͔ • UNUserNoti fi cationCenter.current()ΛςετͰݺͼग़ͯ͠͠·ͬͨ লུ
লུ
Ͳ͏͢ΕΑ͔ͬͨͷ͔
• UNUserNoti fi cationCenter.current()ΛMock͢Δ • Mock͢Δ͜ͱͰ • debug / production
→ UNUserNoti fi cationCenter.current() • test → Mockͨ͠Ϟϊ Ͳ͏͢ΕΑ͔͔ͬͨ
• UserDefaultsͰ͋Ε suiteName Λར༻͢Δ͜ͱͰςετ͢Δࡍʹ debugʹӨڹΛ༩͑ͳ͍Α͏ʹ͢Δ͜ͱ͕Մ • UserDefaults(suiteName: “pixiv_app_night_for_test”) • ͔͠͠ɺUNUserNoti
fi cationCenterʹଘࡏ͠ͳ͍ Ͳ͏ͬͯMock͢Δͷ͔
• protocolΛར༻͢Δ͜ͱͰඪ४APIʹରͯ͠MockΛߦ͑ΔΑ͏ʹ͢Δ ͦ͜Ͱ 6/6TFS/PUJ fi QSPUPDPM 6/6TFS/PUJ fi EFCVHSFMFBTF UFTU
• SchedulerΛ࡞Δ࣌ʹߦ͍ͬͯͨ͜ͱͱಉ༷ͷ͜ͱΛߦ͏ ͦ͜Ͱ
protocolΛఆٛ
ར༻͢ΔϝιουΛఆٛ
ར༻͢ΔϝιουΛఆٛ
extensionΛར༻ͯ͠४ڌͤ͞Δ
Jump to De fi nitionΛ͏ͱָ
Jump to De fi nitionΛ͏ͱָ
Jump to De fi nitionΛ͏ͱָ
Jump to De fi nitionΛ͏ͱָ
extensionΛར༻ͯ͠४ڌͤ͞Δ
Schedulerͷमਖ਼ ͦͷ1
Schedulerͷमਖ਼ ͦͷ1
Schedulerͷमਖ਼ ͦͷ1
• test༻ͷϞσϧੜϝιουΛՃ Schedulerͷमਖ਼ ͦͷ2
• test༻ͷϞσϧੜϝιουΛՃ Schedulerͷमਖ਼ ͦͷ2
Schedulerͷमਖ਼ ͦͷ2 • γϯάϧτϯΫϥεͰ `private init`͕࣮͞Ε͍ͯͨ߹ʹ༗ޮ
Mockͷ࡞
Mockͷ࡞
Mockͷ࡞
Mockͷ࡞
Mockͷ࡞
Mockͷ࡞
Mockͷ࡞
ςετमਖ਼
ςετͷमਖ਼
ςετͷमਖ਼
ςετͷमਖ਼
None
None
None
None
ࠓͦ͜ςετޭ🎉
·ͱΊ
·ͱΊ • Ϣχοτςετ࣌ʹMockΛར༻͠ͳ͍ͱdebugϏϧυʹӨڹΛ༩͑Δ ͜ͱ͕͋Δ • ඪ४APIʹରͯ͠MockΛ͢Δͱ͖protocolΛ࡞ͯ͠ରͷΫϥε ʢΦϒδΣΫτʣʹ४ڌͤ͞Δ
·ͱΊ
·ͱΊ
͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ