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.8k
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
900
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
ITヒヤリハットを整理してみた ~ライフサイクルと原因から考える再発防止策~
koukimiura
1
120
人間の目はかわらない、だからJPEGは30年もつ
yuzneri
12
17k
Android CLI
fornewid
0
190
「正の参照」と 「負の導出」で組む ハーネスエンジニアリング
cottpan
1
150
Lean は証明の正しさを確認するためだけのツールって思ってませんか?
inoueasei
1
120
テーブルをDELETEした
yuzneri
0
120
ここ半年くらいでAIに作らせたR用ツール
eitsupi
0
330
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
430
AIエージェントで 変わるAndroid開発環境
takahirom
2
740
メールのエイリアス機能を履き違えない
isshinfunada
0
140
為什麼你並不需要ViewModel / No, you don't need a ViewModel
lovee
1
440
信頼性について考えてみる(SRE NEXT 2026 miniLT)
hayama17
0
220
Featured
See All Featured
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
200
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.4k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
3
370
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
360
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
A Modern Web Designer's Workflow
chriscoyier
698
190k
Code Review Best Practice
trishagee
74
20k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.5k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
670
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