How to use android.test.servicetestcase correctly?
My application is a service running in / system / APP
com.abc.def.MyApp
Trying to write a unit test for this, I received this error in logcat at runtime
I/TestGrouping( 5647): TestCase class com.abc.def.test.MyAppTest is missing a public constructor with no parameters or a single String parameter - skipping
Commands used:
D:\tmp_install>adb shell am instrument -w com.abc.def.test/android.test.InstrumentationTestRunner
WARNING: linker: memtrack.jacinto6.so: unused DT entry: type 0xf arg 0x115
WARNING: linker: libsrv_um.so: unused DT entry: type 0xf arg 0xc4e
WARNING: linker: gralloc.jacinto6.so: unused DT entry: type 0xf arg 0x5d9
WARNING: linker: libpvr2d.so: unused DT entry: type 0xf arg 0x778
Test results for InstrumentationTestRunner=
Time: 0.0
OK (0 tests)
My code snippet is:
public class MyAppTest extends ServiceTestCase<MyApp> {
public MyAppTest(Class serviceClass) {
super(serviceClass);
Log.d(tag, "Hello World! MyAppTest ctor");
}
public MyApptest() {
super(com.abc.def.MyApp.class);
}
….
I have followed this answer https://stackoverflow.com/a/8981508/398348
Am I using servicetestcase incorrectly?
resolvent:
As far as I know, you are using servicetestcase correctly!
Usually, you only need a constructor without parameters to work properly, and you have provided it
public MyApptest() {
super(com.abc.def.MyApp.class);
}
Linker warnings you receive are usually connected to NDK. They should still not be a problem for your test
Although it is not a complete solution, I suggest you try to run the same tests using gradle connected Android test. If they run normally, at least we know that the problem is with the AM instrument - it may be that the test project is configured incorrectly
Edit: if you use gradle to build a project (by default if you use Android studio), just enter the main project directory and execute the following command to run all instrumentation tests (such as the servicetestcase example above)
./gradlew connectedAndroidTest