Unit Tests, Mock HTTP & UI Tests in Kotlin Compose Desktop | Lesson 15
Автор: Taught by Celeste AI - AI Coding Coach
Загружено: 2026-02-23
Просмотров: 10
Описание:
Learn how to test Kotlin Compose Desktop applications! We refactor a weather app for testability with
injectable HttpClient, add pure functions, and write 16 tests covering unit tests, Ktor MockEngine API
mocking, and Compose UI tests with createComposeRule.
What You'll Learn:
Setting up test dependencies: compose.desktop.uiTestJUnit4, ktor-client-mock, coroutines-test
Refactoring for testability: injectable HttpClient parameter instead of global client
Pure functions for easy unit testing (weatherDescription WMO code mapping)
@Serializable data class deserialization tests with kotlinx-serialization
Ktor MockEngine for controlled HTTP responses without hitting real APIs
Compose UI testing with createComposeRule() and JUnit4
onNodeWithTag / onNodeWithText for querying the semantic tree
Modifier.testTag("id") for stable UI test selectors
assertTextEquals, assertTextContains, assertExists for UI assertions
waitUntil for async operations in UI tests
Testing error states with mock server errors
Timestamps:
0:00 - Introduction
0:15 - Preview: 16 Tests Across 3 Files
0:45 - Project Setup (Gradle with Test Dependencies)
2:48 - Weather Models & API (Refactored for Testability)
5:03 - App Content & Main (with testTag Modifiers)
9:27 - Unit Tests (WeatherModelsTest + WeatherApiTest)
14:18 - UI Tests (AppContentTest with Compose Rules)
17:51 - Run Tests (Compile + ./gradlew test + Results)
19:33 - Live Demo: Weather App in Action
20:13 - Recap & Key Takeaways
21:13 - Thanks for Watching
Key Takeaways:
1. Test Setup — compose.desktop.uiTestJUnit4 + kotlin("test") for desktop UI and unit tests
2. Unit Tests — Test pure functions and serialization with @Test and assertEquals
3. Mock HTTP — Ktor MockEngine replaces real API calls with controlled responses
4. UI Tests — createComposeRule() + onNodeWithTag for composable assertions
5. Test Tags — Modifier.testTag("id") gives stable selectors for UI test queries
Previous Lesson:
Lesson 14: Tables & Data Grids — Data Explorer
/ . .
Next Lesson:
Lesson 16: Packaging & Distribution (coming soon)
Tech Stack:
Kotlin 2.1, Compose Multiplatform 1.7.3, Material3
Ktor 3.0.3, Ktor MockEngine, kotlinx-serialization 1.7.3
JUnit4, kotlinx-coroutines-test 1.9.0
Gradle 8.10, JVM 17+
Source Code: https://github.com/GoCelesteAI/kotlin...
Taught by CelesteAI
If you found this helpful, please like and subscribe for more Kotlin Desktop tutorials!
#kotlin #compose #desktop #material3 #testing #junit #mockengine #ktor #unittests #uitests #tutorial
#programming
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: