~/talk

Custom Coroutine Contexts: Seamless TestDispatcher injection

Talkat droidcon London 2025 · 2025-10-30..10-31· [concurrency, testing]
slides:none on file

Explains a concrete technique that avoids constructor dispatcher injection by adding a custom CoroutineContext element that supplies a DispatcherProvider and makes production code call currentDispatchers.io, so tests can inject a TestDispatcher via runTest; reproduces the example where a 5s timeout test becomes ~69ms. Offers a tiny open-source helper (runTest wrapper and context element) to apply this across a codebase, with caveats for libraries that hardcode dispatchers and for code that breaks structured concurrency.

AI-written summary · about

  1. 0:00Introduction
  2. 1:08Talk overview
  3. 3:54TestDispatchers in unit tests
  4. 6:00Dispatcher replacement options
  5. 9:54Limitations of current solutions
  6. 11:38TestDispatcher injection issue
  7. 12:02CoroutineContext internals
  8. 16:18Access patterns in CoroutineContext
  9. 19:12Context inheritance and evolution
  10. 25:14Custom CoroutineContext element
  11. 26:39TestDispatcher in production
  12. 27:43Custom runTest solution
  13. 28:46Advantages of new approach
  14. 30:52Future plans
  15. 31:47Q&A
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.