Why would the Android Instrumentation Runner fail to find tests in a package?
This is an old and quite large project, and it used to work but now it does not. I have tried creating a brand new test project, and it works fine. I do not know where to start in trying to pinpoint the problem.
Here is the experience I am having:
I run the following on the command line:
am instrument -w -r -e debug false -e class 'com.datmedia.mediaplayertest.ScreenControl.LgTranslatorTests' com.datmedia.mediaplayertest.test/androidx.test.runner.AndroidJUnitRunner
It correctly finds the tests in my LgTranslatorTests
class and runs them.
INSTRUMENTATION_CODE: -1
ts' com.datmedia.mediaplayertest.test/androidx.test.runner.AndroidJUnitRunner <
INSTRUMENTATION_STATUS: numtests=3
INSTRUMENTATION_STATUS: stream=
com.datmedia.mediaplayertest.ScreenControl.LgTranslatorTests:
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: test=readPartialMessage
INSTRUMENTATION_STATUS: class=com.datmedia.mediaplayertest.ScreenControl.LgTranslatorTests
INSTRUMENTATION_STATUS: current=1
INSTRUMENTATION_STATUS_CODE: 1
INSTRUMENTATION_STATUS: numtests=3
INSTRUMENTATION_STATUS: stream=.
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: test=readPartialMessage
INSTRUMENTATION_STATUS: class=com.datmedia.mediaplayertest.ScreenControl.LgTranslatorTests
(...)
INSTRUMENTATION_RESULT: stream=
Time: 0.242
OK (3 tests)
But if I attempt to run all of the tests in the containing package, the test runner fails to find any.
am instrument -w -r -e package com.datmedia.mediaplayertest.ScreenControl -e debug false com.datmedia.mediaplayertest.test/androidx.test.runner.AndroidJUnitRunner
Spits out the following:
INSTRUMENTATION_RESULT: stream=
Time: 0
OK (0 tests)
INSTRUMENTATION_CODE: -1
I found that the tests could run successfully on an Android 11 device but not on an Android 4.4 device.
On the Android 4.4 device (when it fails to locate tests), I get the following warnings and errors:
2023-01-23 10:04:22.074 2910-2910 dalvikvm com.datmedia.mediaplayertest.test W VFY: unable to resolve static method 5065: Landroidx/test/internal/util/ReflectionUtil;.reflectivelyInvokeRemoteMethod (Ljava/lang/String;Ljava/lang/String;)V
2023-01-23 10:04:22.084 2910-2910 dalvikvm com.datmedia.mediaplayertest.test W VFY: unable to resolve instance field 7
2023-01-23 10:04:22.084 2910-2910 dalvikvm com.datmedia.mediaplayertest.test W VFY: unable to resolve virtual method 4699: Landroidx/test/internal/runner/hidden/ExposedInstrumentationApi;.execStartActivity (Landroid/content/Context;Landroid/os/IBinder;Landroid/os/IBinder;Landroid/app/Activity;Landroid/content/Intent;I)Landroid/app/Instrumentation$ActivityResult;
2023-01-23 10:04:22.084 2910-2910 dalvikvm com.datmedia.mediaplayertest.test W VFY: unable to resolve virtual method 4703: Landroidx/test/internal/runner/hidden/ExposedInstrumentationApi;.execStartActivity (Landroid/content/Context;Landroid/os/IBinder;Landroid/os/IBinder;Ljava/lang/String;Landroid/content/Intent;ILandroid/os/Bundle;)Landroid/app/Instrumentation$ActivityResult;
2023-01-23 10:04:26.914 2910-2910 dalvikvm com.datmedia.mediaplayertest.test W VFY: unable to resolve virtual method 122: Landroid/content/pm/PackageManager;.isInstantApp ()Z
2023-01-23 10:04:26.924 2910-2910 dalvikvm com.datmedia.mediaplayertest.test W VFY: unable to resolve virtual method 37: Landroid/app/UiAutomation;.executeShellCommand (Ljava/lang/String;)Landroid/os/ParcelFileDescriptor;
2023-01-23 10:04:27.074 2910-2950 dalvikvm com.datmedia.mediaplayertest.test W Unable to resolve superclass of Landroidx/core/app/CoreComponentFactory; (7)
2023-01-23 10:04:27.074 2910-2950 dalvikvm com.datmedia.mediaplayertest.test W Link of class 'Landroidx/core/app/CoreComponentFactory;' failed
2023-01-23 10:04:27.074 2910-2950 dalvikvm com.datmedia.mediaplayertest.test W Unable to resolve superclass of Landroidx/core/app/CoreComponentFactory; (7)
2023-01-23 10:04:27.074 2910-2950 dalvikvm com.datmedia.mediaplayertest.test W Link of class 'Landroidx/core/app/CoreComponentFactory;' failed
2023-01-23 10:04:27.074 2910-2950 TestLoader com.datmedia.mediaplayertest.test E Could not find class: androidx.core.app.CoreComponentFactory
2023-01-23 10:04:27.364 2910-2950 dalvikvm com.datmedia.mediaplayertest.test W Unable to match class for part: 'Ljava/nio/file/Path;Ljava/lang/String;[Ljava/nio/file/attribute/FileAttribute;)Ljava/nio/file/Path;'
2023-01-23 10:04:27.364 2910-2950 AndroidJUnit4Builder com.datmedia.mediaplayertest.test W java.lang.NoClassDefFoundError: java/nio/file/Path in hasTestMethods for kotlin.io.path.PathsKt__PathUtilsKt
2023-01-23 10:04:27.454 2910-2950 dalvikvm com.datmedia.mediaplayertest.test W Unable to match class for part: 'Ljava/util/stream/Stream;'
2023-01-23 10:04:27.454 2910-2950 AndroidJUnit4Builder com.datmedia.mediaplayertest.test W java.lang.NoClassDefFoundError: java/util/stream/Stream in hasTestMethods for io.reactivex.rxjava3.processors.MulticastProcessor
2023-01-23 10:04:27.684 2910-2950 InfraTrack com.datmedia.mediaplayertest.test W Analytics post: AndroidJUnitRunner=1.1.0 failed.
2023-01-23 10:04:27.694 2910-2950 dalvikvm com.datmedia.mediaplayertest.test W VFY: unable to resolve static method 290: Landroid/os/Trace;.isEnabled ()Z