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
Developing with AI Agents — Codex, Claude Code & Cowork Practical Guide
x5gtrn
PRO
0
1.3k
Spring Security 実践 ─ GraphQL APIで実務に役立つ 認証・認可 を学ぶ
wagyu
0
270
The ROI of Quarkus for Spring Boot Applications
hollycummins
0
150
AI 輔助遺留系統現代化的經驗分享
jame2408
1
1.1k
LLMによるContent Moderationの本番運用の裏側と品質担保への挑戦
suikabar
3
810
AI時代のUIはどこへ行く?その2!
yusukebe
22
7.7k
AI駆動開発を妨げる技術的負債の解消アプローチ / ai-refactoring-approach
minodriven
17
8.3k
Dataformのリポジトリを立ち上げるときにまずやること / dataform-day0-2026
snhryt
0
200
ローカルLLMを使ってB2Bサービスを作っていての学び
yaotti
0
230
スマートグラスで並列バイブコーディング
hyshu
0
270
Snowflake Summitでの新機能 CoCo / CoWork / snowflake-summit-2026-overall-what-new-coco
tatsuhiro
1
210
Webフレームワークの ベンチマークについて
yusukebe
0
190
Featured
See All Featured
New Earth Scene 8
popppiees
3
2.4k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
400
Art, The Web, and Tiny UX
lynnandtonic
304
22k
How to Ace a Technical Interview
jacobian
281
24k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
880
We Are The Robots
honzajavorek
0
260
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
118
120k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
240
Producing Creativity
orderedlist
PRO
348
40k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
260
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
62
44k
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