When running my android unit test (not instrumente...
# coroutines
m
When running my android unit test (not instrumented). I get this stack trace printed when trying to set the dispatcher in my setup function. The test passes, but this makes the build output very noisy. Anyone know if I'm doing something wrong. The exception says to call
Dispatchers.setMain
, but that is the function creating the stack trace.
c
the exception is from
TestDispatchers
not
Dispatchers
m
I understand how to use
setMain
and I'm trying to use it. What seems to be happening is
setMain
grabs a copy of the current Main to support
resetMain
, but getting the current version fails and that failure gets logged. Is there something that I can do to prevent this behavior.
c
a code snipped how you use it might help 😉
m
Copy code
@Before
    override fun setUp() {
        Dispatchers.setMain(Dispatchers.Unconfined)
        viewportManager.setUp()
    }

    @After
    override fun tearDown() {
        if (this::viewport.isInitialized) {
            viewport.dispose()
        }

        viewportManager.tearDown()
        Dispatchers.resetMain()
    }
Copy code
The stack trace points to my call of `Dispatchers.setMain(Dispatchers.Unconfined)`
c
as mentioned in the docs
Using TestDispatcher as an argument has special behavior: subsequently-called runTest, as well as TestScope and test dispatcher constructors, will use the TestCoroutineScheduler of the provided dispatcher.
m
I don't think that will make a difference because the
setMain
function doesn't look at the dispatcher type. Trying to run again, but it is no longer printing this stack trace even though I didn't change anything.
👍 1