Skip to content

Hilt: No JaCoCo test coverage on @AndroidEntryPoint classes. #1982

@goldy1992

Description

@goldy1992

Given a class

@AndroidEntryPoint
MyActivity : AppCompatActivity()

and a test class

@HiltAndroidTest
@RunWith(RobolectricTestRunner::class)
@LooperMode(LooperMode.Mode.PAUSED)
class MyActivityTest() {
    private lateinit var scenario : ActivityScenario<MainActivity>

    @Rule
    @JvmField
    val rule : HiltAndroidRule = HiltAndroidRule(this)

    @Before
    fun setup() {
        rule.inject()
        scenario = ActivityScenario.launch(MyActivity::class.java)
    }

    @Test
    fun myActivityTest() {
        scenario.onActivity { activity: MyActivity ->
        // test code
        }
   }
  // .. rest of test class
}

and given JaCoCo Gradle Plugin version 0.8.5

Expected: Some code coverage on MyActivity class.
Actual:: 0% coverage

Notes:

  • The coverage worked fine before the hilt plugin migration
  • Given the same scenario with
    @AndroidEntryPoint MyActivity : MyActivityBase() where class ÀctivityBase : AppCompatActivity() There is coverage reported on ActivityBase but not on MyActivity.

This is surely to do with the fact that Hilt is adding an injecting class between MyActivity and it's super class.

This is a Generic example, please tag me if you require any more information.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions