google / dagger

A fast dependency injector for Android and Java.
https://dagger.dev
Apache License 2.0
17.41k stars 2.01k forks source link

After integrating HiltRunner, it's always say 0 tests passed for instrumentation tests #3223

Closed androidcodehunter closed 2 years ago

androidcodehunter commented 2 years ago

I am trying to write UI test using Hilt. When using androidx.test.runner.AndroidJUnitRunner tests always run with status passed or failed but when using mypackage.HiltTestRunner it's always 0 tests passed for any test cases under @HiltAndroidTest. Here is the class I am using to get the AndroidJUnitRunner,

class HiltTestRunner : AndroidJUnitRunner() {

    override fun newApplication(cl: ClassLoader?, name: String?, context: Context?): Application {
        return super.newApplication(cl, HiltTestApplication::class.java.name, context)
    }
}

I included the AndroidJUnitRunner in my gradle like this testInstrumentationRunner = "com.pinwheel.desktop.HiltTestRunner"

To check hilt test integration I am running a sample activity like this,

@HiltAndroidTest
class WarningActivityTest {

    @get:Rule(order = 0)
    var hiltRule = HiltAndroidRule(this)

    @Test
    fun check() {
        Timber.d("Testing running check")
        hiltRule.inject() 
        val scenario = launchActivity<WarningActivity>()
    }
}

Whatever I run it always say 0 tests passed. Here is the screenshoot from android studio bumblebeee,

warning test

danysantiago commented 2 years ago

Can you check your device's Logcat? It might be that some exception is occurring during test startup and showing in Studio as 'no tests ran'.

androidcodehunter commented 2 years ago

@danysantiago actually logcat not showing anything though I run this command and got this error

adb shell am instrument -w -m    -e debug false -e class 'com.pinwheel.desktop.NormalTestCheck#doRunTest' ```
com.pinwheel.desktop.test/com.pinwheel.desktop.HiltTestRunner

" shortMsgProcess crashed.

androidcodehunter commented 2 years ago

@danysantiago I dig into more about this issue. I am using ContentProvider where I am using Room database injection using EntryPoint. Once I remove inject from contentprovider everything works fine otherwise it just runs indefinitely. Thanks for your time.

danysantiago commented 2 years ago

Ok, glad you were able to figure it out!