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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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.3k
Refreshable API を TCA で使う
kalupas226
0
290
Combineを使ったコードのテストをSchedulerで操る方法とその仕組み
kalupas226
2
1.9k
Composable FormsでTCAのボイラープレートとおさらばする
kalupas226
1
1.3k
Swiftの関数と代数学
kalupas226
0
870
Swiftのstruct・enumと代数学_part1
kalupas226
2
1.6k
Examples の Search プロジェクトから学ぶ The Composable Architecture
kalupas226
0
450
Other Decks in Programming
See All in Programming
決定論的オーケストレーションの設計と実装 / Design and Implementation of Deterministic Orchestration
nrslib
3
1.2k
メソッドのジェネリクスでGoの夢は広がるか? / Kyoto.go #65
utgwkk
3
640
Semantic Version 単位で戦略を柔軟に変えて、パッケージアップデートを自動化する
daitasu
0
180
Old Dog, New Tricks: The Java 25 Reinvention - JNation
bazlur_rahman
0
150
LLM本来の能力を解き放つサンドボックス技術とAI民主化への適用
yukukotani
3
3.4k
TAKTでAI駆動開発の品質を設計する
j5ik2o
6
1.1k
軽量Java基盤の設計 DIコンテナに頼らない、長期保守と1秒起動の実現 JJUG CCC 2026 Spring
macha64
0
480
ECSアプリログをFireLensでコスト削減しようとしたけど諦めた話 in Fargate×Node.js
akihisaikeda
2
3.9k
プロパティの順序で型推論が壊れる!? TypeScript6.0の修正からContext-Sensitivityの仕組みを追う
bicstone
2
1.3k
生成AI時代にこそ効くGo | Why Go Works in the Age of Generative AI
mom0tomo
8
3.2k
「エンジニアインターン、どうやって取った?」準備のリアルを語るLT会 Progate BAR
akiomatic
0
120
RTSPクライアントを自作してみた話
simotin13
0
520
Featured
See All Featured
Game over? The fight for quality and originality in the time of robots
wayneb77
1
190
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.8k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
530
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
410
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
240
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
250
Visualization
eitanlees
152
17k
A Modern Web Designer's Workflow
chriscoyier
698
190k
Thoughts on Productivity
jonyablonski
76
5.2k
Faster Mobile Websites
deanohume
310
31k
Accessibility Awareness
sabderemane
1
130
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
380
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