Leveraging Kotlin to write maintainable UI tests
summary
Concrete claim: a Kotlin DSL yields readable, compiler-checked Espresso integration tests that are easy to change and less flaky. Implementation uses Kotlin DSL with @DslMarker, extension functions, delegates and scoped receivers, espresso helpers and a three-layer UI test / DSL / helpers architecture. Determinism comes from an on-device OkHttp MockWebServer driven by Hamcrest matchers. Examples and a working repository are published and the DSL proves practical for RecyclerView item assertions and focused code completion.
AI-written summary · about
chapters (22)
- 0:00Intro
- 0:49Goals
- 1:57Example system under test
- 3:11Simple function
- 3:46Implicit receiver
- 4:31Higher-order function with receiver
- 5:16Motivation
- 6:06Gwen structured code
- 6:39Gwen: implementation
- 9:31Summary. Easy to read
- 10:53Gwen: scoped collaborators
- 11:50Actions: scoped groups
- 13:38Actions: scoped by screen
- 16:12DSL scoping: Collaborators
- 18:54Layered separation: example action
- 19:41Layered separation, example setup
- 21:01Scoped layout: syntactic sugar
- 22:19Scoped layout: delegate
- 23:44Scoped layout: structure
- 25:00Summary. Easy to change
- 29:58User Collaborator
- 35:12Scoped layout: implementation
related talks
30mKotlin DSLs
48mKotlin DSLs
41mTesting in Kotlin: The Holy Grail of Readability and Power
53mSolving Espresso Android Autotest Issues in the Real World
45mKotlin DSL in under an hour
28mTesting Out Kotlin
42mRock-Solid UI and Instrumentation Testing
44mKotlin DSL as a single source of truth for solving many tasks
