3

My app is a Service that runs in /system/app

com.abc.def.MyApp

Trying to write unit tests for it, I get this error in the logcat while running.

I/TestGrouping( 5647): TestCase class com.abc.def.test.MyAppTest is missing a public constructor with no parameters or a single String parameter - skipping

command 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 snippet of code 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?

Community
  • 1
  • 1
likejudo
  • 3,396
  • 6
  • 52
  • 107

2 Answers2

2

From what I see, you're using ServiceTestCase correctly!

Generally all you need is the constructor with no parameters for it to work correctly and you've provided it.

public MyAppTest() {
    super(com.abc.def.MyApp.class);
}

The linker warnings you get are usually connected with the NDK. Still they shouldn't be a problem for you tests.

Although not a complete solution, I suggest you try running the same tests with gradle connectedAndroidTest. If they run properly, at least we know the problem is with the am instrument - perhaps not correctly configured TEST project.

EDIT: If you're using Gradle to build your project (by default if you're using Android Studio), just go into your main project directory and execute the following command, which will run all your Instrumentation tests (like the ServiceTestCase example above).

./gradlew connectedAndroidTest
Vesko
  • 3,750
  • 2
  • 23
  • 29
  • It's not a linker warning - it skips the tests. if you agree my question is valid, then please upvote the question so it will get attention. someone has downvoted this to negative. – likejudo Nov 02 '15 at 22:21
  • It's valid question indeed. Still I wonder why is it skipped altogether? Same thing with Gradle? – Vesko Nov 02 '15 at 22:22
  • I don't know how to run from gradle. Where will the tests run? Currently they are installing on device and should run on device. – likejudo Nov 02 '15 at 22:26
  • Check my edited answer. Invoking this command will build the app, install it on a connected device/emulator and execute the tests automatically. The detailed output (results) can be found under app/build/reports/androidTests/ – Vesko Nov 02 '15 at 22:46
  • I am using a makefile to build my project. – likejudo Nov 03 '15 at 15:44
  • using gradle is not an option for me – likejudo Nov 09 '15 at 20:37
1

As Vesko said, the code is correct; however root cause of the problem was Dex preOptimization - updates to my code were not showing up in the behavior of the runtime.

Solution? I had to push the odex file as well as the apk to the device.

likejudo
  • 3,396
  • 6
  • 52
  • 107