question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Integrate test dispatchers with libraries using Dispatchers.Xxx

See original GitHub issue

Make sure that libraries can use hard-coded withContext(Dispatchers.IO) { ... } and still be testable with test dispatchers. See also discussion in #810 and #1202.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:83
  • Comments:15 (5 by maintainers)

github_iconTop GitHub Comments

22reactions
CharlyLafon37commented, Aug 29, 2019

Any update on this issue ?

9reactions
wkornewaldcommented, Dec 30, 2021

We do have retry handling and other code that needs to work around limitations of underlying libraries with delay and those can happen inside non-Main dispatchers. It would be really great to have the possibility to not just set the main dispatcher but really all dispatchers. Currently we still depend on a wrapper (e.g. dispatchers.io instead of Dispatchers.IO) to have full control and a well-defined test environment. Does anything speak against just providing a simple Dispatchers.setAll(dispatcher)?

Also, it would be really awesome to have some utility to make setting up coroutine-capable unit tests trivially easy. Ideally, the default behavior in unit tests would automatically switch all dispatchers and the test lib would provide a global singleton default testScope. If anyone needs more control it’s still possible to modify the default setup and use custom testScopes.

If having nice default behavior automatically is impossible, then it would be great to have something like a CoroutineTest base class or delegate or a test rule that can be added to any existing test class in as little code as possible to get the nice defaults. Anything that doesn’t require repeating that boilerplate and learning unnecessary details just to get started would be great.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Possibility to replace default dispatchers · Issue #810 - GitHub
Replacing dispatcher implementation is pretty common thing which of course ... Integrate test dispatchers with libraries using Dispatchers.
Read more >
Set up local Dispatcher Tools - AEM
AEM SDK's Dispatcher Tools facilitates the local development of Adobe Experience Manager (AEM) projects by making it easy to install, ...
Read more >
Testing support - Spring
The Spring Integration Test Framework and test utilities are fully based on existing JUnit, Hamcrest, and Mockito libraries. The application context interaction ...
Read more >
Use Kotlin Coroutines in your Android App - Android Developers
This exercise shows you how to test coroutines running on Dispatchers. Main using the kotlinx-coroutines-test library. Later in this codelab ...
Read more >
How could I write tests for uncovered lines in useEffect and ...
I succeeded in writing the test : adding inputProps={{ id: "trimInput" }} to ... /></Provider>); store.dispatch = jest.fn(); await act(async ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found