我的应用程序是在/system/app 中运行的服务
com.abc.def.MyApp
尝试为其编写单元测试时,我在运行时在 logcat 中收到此错误。
I/TestGrouping( 5647): TestCase class com.abc.def.test.MyAppTest is missing a public constructor with no parameters or a single String parameter - skipping
使用的命令:
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)
我的代码 fragment 是:
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);
}
....
我遵循了这个答案 https://stackoverflow.com/a/8981508/398348
我是否错误地使用了 ServiceTestCase?
最佳答案
据我所知,您正确使用了 ServiceTestCase
!
通常,您只需要没有参数的构造函数即可正常工作,而您已经提供了它。
public MyAppTest() {
super(com.abc.def.MyApp.class);
}
您收到的linker
警告通常与 NDK 相关。对于您的测试来说,它们仍然不是问题。
虽然不是完整的解决方案,但我建议您尝试使用 gradle connectedAndroidTest
运行相同的测试。如果它们运行正常,至少我们知道问题出在 am instrument
- 可能配置不正确 TEST project .
编辑:如果您使用 Gradle
构建您的项目(默认情况下,如果您使用的是 Android Studio),只需进入您的主项目目录并执行以下命令,该命令将运行您所有的 Instrumentation 测试(如上面的 ServiceTestCase
示例)。
./gradlew connectedAndroidTest
关于android - 如何正确使用android.test.ServiceTestCase?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33311533/