google / dagger

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

Does Hilt always execute app module during instrumented test? #4354

Open ArcherEmiya05 opened 4 months ago

ArcherEmiya05 commented 4 months ago

I just migrated a project from Dagger to Hilt, everything works fine except when executing ./gradlew connectedAndroidTest with AVD running in a CI CD pipeline. There is this bug we are experiencing when running such tests in pipeline that we previously solved by modularizing the project so the app module no longer contains any instrumented test.

However after migrating to Hilt and using it to inject dependency in each module's instrumented test, the bug started to show again. The instrumented test on each modules are success but for some reason the task :app:connectedDebugAndroidTest is also getting executed again despite not having a androidTest.

I also tried to specify which module runs instrumented test yet it keeps running the task for app module. This does not happen when using Dagger.

./gradlew module1:connectedAndroidTest module2:connectedAndroidTest

image

> Task :AndroidCommon:connectedDebugAndroidTest

Starting 3 tests on EMU(AVD) - 6.0

Finished 3 tests on EMU(AVD) - 6.0

> Task :AndroidCommon:connectedAndroidTest

> Task :Messari:connectedDebugAndroidTest

additionalTestOutput is not supported on this device running API level 23 because the additional test output directory could not be found

Starting 29 tests on EMU(AVD) - 6.0

EMU(AVD) - 6.0 Tests 8/29 completed. (0 skipped) (0 failed)

EMU(AVD) - 6.0 Tests 16/29 completed. (0 skipped) (0 failed)

Finished 29 tests on EMU(AVD) - 6.0

> Task :Messari:connectedAndroidTest

> Task :WordPress:connectedDebugAndroidTest

additionalTestOutput is not supported on this device running API level 23 because the additional test output directory could not be found

Starting 10 tests on EMU(AVD) - 6.0

EMU(AVD) - 6.0 Tests 10/10 completed. (0 skipped) (0 failed)

Finished 10 tests on EMU(AVD) - 6.0

> Task :WordPress:connectedAndroidTest

> Task :YouTube:connectedDebugAndroidTest

additionalTestOutput is not supported on this device running API level 23 because the additional test output directory could not be found

Starting 10 tests on EMU(AVD) - 6.0

Finished 10 tests on EMU(AVD) - 6.0

> Task :YouTube:connectedAndroidTest

> Task :app:connectedDebugAndroidTest

additionalTestOutput is not supported on this device running API level 23 because the additional test output directory could not be found

Finished 0 tests on EMU(AVD) - 6.0

> Task :app:connectedDebugAndroidTest

There were failing tests. See the report at: file:///opt/atlassian/pipelines/agent/build/app/build/reports/androidTests/connected/debug/index.html

> Task :app:connectedAndroidTest

Exception thrown during onBeforeAll invocation of plugin AndroidTestApkInstallerPlugin: ErrorName: UNKNOWN

NameSpace: DdmlibAndroidDeviceController

ErrorCode: 1

ErrorType: TEST

Message: Failed to install split APK(s): [/opt/atlassian/pipelines/agent/build/app/build/outputs/apk/debug/app-debug.apk]

Failed to install split APK(s): [/opt/atlassian/pipelines/agent/build/app/build/outputs/apk/debug/app-debug.apk]

Unknown platform error occurred when running the UTP test suite. Please check logs for details.

com.android.ddmlib.ShellCommandUnresponsiveException

    at com.android.ddmlib.internal.DeviceImpl.lambda$executeRemoteCommand$18(DeviceImpl.java:891)

    at com.android.ddmlib.internal.DeviceImpl.logRun1(DeviceImpl.java:1801)

    at com.android.ddmlib.internal.DeviceImpl.executeRemoteCommand(DeviceImpl.java:755)

    at com.android.ddmlib.SplitApkInstallerBase.installCommit(SplitApkInstallerBase.java:154)

    at com.android.ddmlib.SplitApkInstaller.install(SplitApkInstaller.java:85)

    at com.android.ddmlib.IDeviceSharedImpl.installPackages(IDeviceSharedImpl.java:395)

    at com.android.ddmlib.internal.DeviceImpl.lambda$installPackages$34(DeviceImpl.java:1491)

    at com.android.ddmlib.internal.DeviceImpl.logRun3(DeviceImpl.java:1833)

    at com.android.ddmlib.internal.DeviceImpl.installPackages(DeviceImpl.java:1488)

    at com.android.ddmlib.internal.DeviceImpl.lambda$installPackages$35(DeviceImpl.java:1503)

    at com.android.ddmlib.internal.DeviceImpl.logRun3(DeviceImpl.java:1833)

    at com.android.ddmlib.internal.DeviceImpl.installPackages(DeviceImpl.java:1499)

    at com.android.tools.utp.plugins.deviceprovider.ddmlib.DdmlibAndroidDevice.installPackages(DdmlibAndroidDevice.kt:74)

    at com.android.tools.utp.plugins.deviceprovider.ddmlib.DdmlibAndroidDeviceController$executeAsync$deferred$1.invokeSuspend(DdmlibAndroidDeviceController.kt:259)

    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)

    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)

    at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)

    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:749)

    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)

    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
bcorso commented 4 months ago

Hmm, I don't know.Since there's nothing in the logs hinting to Hilt or Dagger, I don't think there is anything actionable we can do with this, unfortunately.

bcorso commented 4 months ago

Does Hilt always execute app module during instrumented test?

Do you have a Gradle scan? That should tell you why the task is running

ArcherEmiya05 commented 4 months ago

Does Hilt always execute app module during instrumented test?

Do you have a Gradle scan? That should tell you why the task is running

May I know how to do this part? I am not sure if this is what you are looking for but I saw some hilt task on app module that I just didn't include in the first log.

image image