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.4k
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
Spec-Driven Development with AI-Agents: From High-Level Requirements to Working Software
antonarhipov
2
490
生成AI時代にこそ効くGo | Why Go Works in the Age of Generative AI
mom0tomo
8
3.2k
Java × distroless で 軽量なコンテナイメージを / Java on Distroless
contour_gara
0
520
The NotImplementedError Problem in Ruby
koic
1
700
肥大化するレガシーコードに立ち向かうためのインターフェース分離と依存の逆転 / JJUG CCC 2026 Spring
hirokunimaeta
0
530
Technical Debt: Understanding it Rightly, Engaging it Rightly #LaravelLiveJP
shogogg
0
210
LLM Plugin for Node-REDの利用方法と開発について
404background
0
170
代数的データ型って何が嬉しいの? #frontend_phpcon_do
kajitack
8
3.3k
AIとASP.NET Coreで雑Webアプリを作った話
mayuki
0
500
Javaの型とAI時代に型が大事な理由 / java types and type in AI era
kishida
2
120
「AIで開発し、AIを届ける」をEvalでつなぐ 〜AIネイティブに始めるプロダクト開発の実践〜 / Connecting "Develop with AI, deliver AI" with Eval
rkaga
4
4.9k
Why Laravel apps break—Mastering the fundamentals to keep them maintainable
kentaroutakeda
1
350
Featured
See All Featured
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
610
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.3k
Everyday Curiosity
cassininazir
0
230
The Language of Interfaces
destraynor
162
27k
Design in an AI World
tapps
1
240
Speed Design
sergeychernyshev
33
1.8k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.5k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
160
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.5k
My Coaching Mixtape
mlcsv
0
140
Building an army of robots
kneath
306
46k
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