TEJVONTechnologies Pvt. Ltd.
Back to Insights
Android · Testing 1 min readAugust 2026

The tests passed alone and failed together

Every test in the class passed when run individually. Run the whole class and it failed. The cause was a coroutine that outlived its test.

T

Surendra — Tejvon

Senior Android & BLE Engineer

We had a test class for an MVI view model, written with the Orbit library, where every test passed when run on its own. Running the whole class failed.

That pattern almost always means shared state. One test leaves something behind and a later test trips over it. The difficulty is finding what was left behind, because the test that fails is rarely the test that caused it.

The cause here was coroutines. Some tests were missing the runTest wrapper. Without it, coroutines launched during the test were not tied to the test's lifetime. They kept floating after the test finished and corrupted the state of the test dispatcher for whichever test ran next.

The fix was small: wrap every test that touches coroutines in runTest, so that the test waits for its work and cleans up after itself. The class passed in full afterwards.

Two habits came out of it. Always run the whole class, and the whole suite, before trusting a green tick on a single test. And when tests depend on the order they run in, look first at anything asynchronous that could still be alive after a test returns.

Topics

AndroidTesting

Working on a similar challenge?

Let's discuss the architecture before you build.

BLE system design, OTA reliability, and connected product engineering — this is what TEJVON does every day.

Book a Technical Consultation