title: Coroutines body does not cover in unit test code coverage - Android Studio
body: <p>When I run the unit test with code coverage, in the code coverage report lambda is shown as not covered.</p>
  
  <p><a href="https://i.stack.imgur.com/zseKe.png" rel="noreferrer"><img src="https://i.stack.imgur.com/zseKe.png" alt="Code Coverage"></a></p>
  
  <p>Below is my code:</p>
  
  <pre><code>open class CoroutineContextProvider {
      open val main: CoroutineContext by lazy { Dispatchers.Main }
      open val io: CoroutineContext by lazy { Dispatchers.IO }
  }
  </code></pre>
  
  <pre><code>class Hello (
      private val contextProvider: CoroutineContextProvider
  ) {
      private val mScope = CoroutineScope(contextProvider.main)
  
      var value: Int = 0
  
      fun test() {
          mScope.launch(contextProvider.io) {
              println("THIS LINE IS NOT COVERED IN CODE COVERAGE.")
              value++
          }
      }
  }
  
  </code></pre>
  
  <pre><code>class TestCoroutineContextProvider: CoroutineContextProvider() {
      override val main: CoroutineContext
          get() = Dispatchers.Unconfined
      override val io: CoroutineContext
          get() = Dispatchers.Unconfined
  }
  </code></pre>
  
  <pre><code>class CoroutineTestRule: TestRule {
      private val testCoroutineDispatcher = TestCoroutineDispatcher()
      private val testCoroutineScope = TestCoroutineScope(testCoroutineDispatcher)
  
      override fun apply(base: Statement, description: Description?) = object: Statement() {
          override fun evaluate() {
              Dispatchers.setMain(testCoroutineDispatcher)
              base.evaluate()
              Dispatchers.resetMain()
              testCoroutineDispatcher.cleanupTestCoroutines()
          }
      }
  
      fun runBlockingTest(block: suspend TestCoroutineScope.() -&gt; Unit) {
          testCoroutineScope.runBlockingTest { block() }
      }
  }
  </code></pre>
  
  <pre><code>class HelloTests {
  
      @get:Rule
      val instantExecutorRule = InstantTaskExecutorRule()
  
      @get:Rule
      val coroutineTestRule = CoroutineTestRule()
  
      @Test
      fun verify_test() = coroutineTestRule.runBlockingTest {
          val hello = Hello(TestCoroutineContextProvider())
          hello.test()
          assertTrue(hello.value == 1)
      }
  }
  </code></pre>