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
DocC Tutorial と TCA におけるテスト機能の紹介
Search
Aikawa
March 18, 2024
Programming
1.7k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
DocC Tutorial と TCA におけるテスト機能の紹介
TCAわいわいLT会の資料です。
Aikawa
March 18, 2024
More Decks by Aikawa
See All by Aikawa
Swift愛好会WWDC要約会 Build programmatic UI with Xcode Previews
kalupas226
2
890
enum で KeyPaths のような機能を実現する CasePaths
kalupas226
4
1k
SwiftUI Navigation のすべて
kalupas226
11
9.4k
Refreshable API を TCA で使う
kalupas226
0
300
Combineを使ったコードのテストをSchedulerで操る方法とその仕組み
kalupas226
2
1.9k
Composable FormsでTCAのボイラープレートとおさらばする
kalupas226
1
1.3k
Swiftの関数と代数学
kalupas226
0
880
Swiftのstruct・enumと代数学_part1
kalupas226
2
1.6k
Examples の Search プロジェクトから学ぶ The Composable Architecture
kalupas226
0
460
Other Decks in Programming
See All in Programming
生成AI時代にこそ効くGo | Why Go Works in the Age of Generative AI
mom0tomo
8
3.4k
Mujeres en SEO Summit 2026 - Greatest Disaster Hits en Web Performance
guaca
0
220
Semantic Version 単位で戦略を柔軟に変えて、パッケージアップデートを自動化する
daitasu
1
320
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
3
2.6k
Creating Composable Callables in Contemporary C++
rollbear
0
180
気づいたらRubyで100作品 ー クリエイティブコーディングが生活の一部になるまで / 100 Ruby Sketches Later: How Creative Coding Became Part of My Life
chobishiba
3
620
Datadog × OpenTelemetry 入門と実践のあいだ
kn_to_maxpno
1
180
セキュリティの専門家じゃなくてもできる。「セキュリティ意識」をアップデートして サプライチェーン攻撃への耐性を高めよう。
tk3fftk
5
1k
Honoでのサプライチェーン侵害対策 〜 3つのライブラリに学ぶ
yusukebe
7
1.6k
Even G2とAWSで推しのエージェントを召喚しよう!
har1101
1
140
「なぜそう決めたのか」を残し続ける仕組み ― Notion AI カスタムエージェント × Slack連携による設計判断の自動記録 - NIKKEI Tech Talk #47
niftycorp
PRO
0
250
ランチタイムLT会3周年!ランチタイムLT会を3年間続けられたお話
y0hgi
1
120
Featured
See All Featured
How to train your dragon (web standard)
notwaldorf
97
6.7k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
230
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
650
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
630
エンジニアに許された特別な時間の終わり
watany
107
250k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
Odyssey Design
rkendrick25
PRO
2
710
sira's awesome portfolio website redesign presentation
elsirapls
0
290
Six Lessons from altMBA
skipperchong
29
4.3k
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
180
Paper Plane
katiecoart
PRO
1
52k
Transcript
DocC Tutorial ͱ TCA ʹ͓͚Δςετػೳͷհ TCA ͰΘ͍Θ͍ LT ձ ΞΠΧϫ
DocC Tutorial
None
https://github.com/kalupas226/ tca-workshop
https://lu.ma/9a52kvnm
νϡʔτϦΞϧͷߏ • 4 Chapter Ͱ TCA ͷجຊʙ࣮ફతͳࣝΛʹ͚Δ͜ͱ͕Ͱ͖Δ • TCA 1.9.2
ʹରԠࡁΈ (2024/03/17 ࣌) • GitHub Actions Ͱ push ͷʹ GitHub Pages ʹσϓϩΠ͞ΕΔঢ়ଶʹͳ͓ͬͯΓɺ ΠϕϯτͷλΠϛϯάͰϒϥογϡΞοϓ͍ͯ͠Δ • DocC ʹΑΔνϡʔτϦΞϧ࡞ͷࢀߟʹͳΔ͔ • `Sources/Docs` ʹશͯͷϑΝΠϧ͕͋Γ·͢ • Xcode 15 ͷ DocC Preview ͕ͳ͚Ε࡞Δͷ͕ݫ͔ͬͨ͠…
TCA ͷςετػೳ
The testability of features built in the Composable Architecture is
the #1 priority of the library. https://pointfreeco.github.io/swift-composable-architecture/main/documentation/composablearchitecture/testing/
TCA ͷςετ let store = TestStore(initialState: Feature.State(count: 0)) { Feature()
}
ཏੑ (Exhaustivity) ͷ͋Δςετ͕Մೳ let store = TestStore(initialState: Feature.State(count: 0)) {
Feature() } await store.send(.incrementButtonTapped)
ཏੑ (Exhaustivity) ͷ͋Δςετ͕Մೳ let store = TestStore(initialState: Feature.State(count: 0)) {
Feature() } await store.send(.incrementButtonTapped) { $0.count = 1 }
TCA ʹ͓͚Δςετͷཏੑ (Exhaustivity) • ཏੑΛอͬͯςετΛॻ͚Δ͜ͱ TCA ͷେ͖ͳϝϦοτ • ͔͠͠ɺίʔυͷنʹΑͬͯɺཏੑ͕ٯޮՌʹͳΔ͜ͱ͋Δ •
ಛʹ TCA ͷੑ্࣭ɺΞϓϦͷ Root feature ΄ͲཏੑΛอͪͳ͕Β ςετΛॻ͘͜ͱ͕͘͠ͳΓ͕ͪ
Root Feature (App) → Child Feature (Login) ʹ ͓͚Δςετͷཏੑͷྫ await
store.send(\.login.submitButtonTapped) { // 1⃣ Ϣʔβʔͷ submit button λοϓΛΤϛϡϨʔτ͢Δɻ $0.login?.isLoading = true // 2⃣ login feature ͷͯ͢ͷঢ়ଶͷมߋΛ assertion ͢Δɻ // ... } await store.receive(\.login.loginResponse.success) { // 3⃣ login feature Ͱ API ϦΫΤετ͕ߦΘΕΔͨΊɺͦͷϋϯυϦϯά͕ඞཁɻ $0.login?.isLoading = false // 4⃣ login feature ͷͯ͢ͷঢ়ଶͷมߋΛ assertion ͢Δɻ // ... } await store.receive(\.login.delegate.didLogin) { // 5⃣ login feature ϩάΠϯ͕ޭͨ͜͠ͱΛ Delegate Action Λ௨ͯ͡ʹ͑Δɻ // 6⃣ app feature ͷͯ͢ͷঢ়ଶͷมߋΛ assertion ͢Δɻ $0.authenticatedTab = .loggedIn( Profile.State(...) ) // 7⃣ ࠷ऴతʹλϒͷঢ়ଶ͕มߋ͞ΕΔ͜ͱΛ assertion ͯ͠ςετऴྃɻ $0.selectedTab = .activity }
Exhaustivity Λ o ff ʹͯ͠ Root Feature ͷ ݶΒΕͨ෦͚ͩͷςετΛߦ͏ store.exhaustivity
= .off // ⬅ // Ϣʔβʔͷ submit button λοϓΛΤϛϡϨʔτ͢Δɻ await store.send(\.login.submitButtonTapped) // ࠷ऴతʹ login feature ʹΑͬͯϩάΠϯ͕ޭͨ͜͠ͱ͕ app feature ʹΘΓɺ // ͦΕʹΑΓى͖ΔมߋΛ assertion ͢Δ͚ͩͱͳΔɻ await store.receive(\.login.delegate.didLogin) { $0.selectedTab = .activity }
Exhaustivity Λ o ff ʹ͢Δ࣌ͷςΫχοΫ • ར༻ Root دΓͷ Feature
͚ͩʹཹΊΔ • `off(showSkippedAssertions:)` • Exhaustivity Λ off ʹͭͭ͠ skip ͞ΕͨͷΛදࣔ͢Δ • `withExhaustivity(_:operation:)` • ෦తʹ exhaustivity Λ off ʹͯ͠ςετͰ͖Δ • `skipReceivedActions(strict: fi le:line)` • ड͚औͬͨ action Λશͯ skip ͢Δ • `assert(_: fi le:line:)` • Store ͷঢ়ଶͷ assertion ͕ՄೳͰɺಛʹ Store ͷ࠷ऴঢ়ଶΛ assertion ͢Δͷʹศར
TCA ͰςετΛॻ্͘Ͱཱͭଞͷ • `withDependencies(_:operation:)` • ෦తʹґଘΛॻ͖͑ͯςετ͢Δ • `useMainSerialExecutor` • Async
ͳฒྻॲཧΛϝΠϯεϨουͰॲཧ͠ςελϒϧʹ͢Δ • ࠓͷ TCA σϑΥϧτͰ͜ͷػೳ͕༗ޮʹͳ͍ͬͯΔ • Non-exhaustive testing ͷҙ • https://pointfreeco.github.io/swift-composable-architecture/main/documentation/ composablearchitecture/testing#Non-exhaustive-testing