每次我开始我的Android检测测试时都会失败
android.test.suitebuilder.TestSuiteBuilder$FailedToCreateTests:
Error in testSuiteConstructionFailed:
java.lang.RuntimeException: Exception during suite construction
at android.test.suitebuilder.TestSuiteBuilder$FailedToCreateTests.testSuiteConstructionFailed(TestSuiteBuilder.java:239)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:520)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1447)
Caused by: java.lang.reflect.InvocationTargetException
at com.samy4me.test.Test_Service2.<init>(Test_Service2.java:26)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
at android.test.suitebuilder.TestMethod.instantiateTest(TestMethod.java:87)
at android.test.suitebuilder.TestMethod.createTest(TestMethod.java:73)
at android.test.suitebuilder.TestSuiteBuilder.addTest(TestSuiteBuilder.java:263)
at android.test.suitebuilder.TestSuiteBuilder.build(TestSuiteBuilder.java:185)
at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:373)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4218)
at android.app.ActivityThread.access$3000(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2071)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NoClassDefFoundError: com.XXX.ws.Service
... 19 more
班级在那里。我检查了ProGuard,我暂时停用了ProGuard。我将测试降低到绝对最小值:
public class Test_Service2
extends android.test.ServiceTestCase<Service>
{
public Test_Service2 ()
{
super (Service.class);
} // Test_Service2
} // Test_Service2
有人知道这可能是怎么发生的吗?
仔细观察我现在发现了以下内容:
04-23 15:56:21.186 W/ClassPathPackageInfoSource( 580): Caused by: java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
04-23 15:56:21.186 W/ClassPathPackageInfoSource( 580): at dalvik.system.DexFile.defineClass(Native Method)
04-23 15:56:21.186 W/ClassPathPackageInfoSource( 580): at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:209)
04-23 15:56:21.186 W/ClassPathPackageInfoSource( 580): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:203)
04-23 15:56:21.186 W/ClassPathPackageInfoSource( 580): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
04-23 15:56:21.186 W/ClassPathPackageInfoSource( 580): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
04-23 15:56:21.186 W/ClassPathPackageInfoSource( 580): ... 26 more
这是原始错误异常链的一部分,但被截断。预先验证的异常并不是新的,也是Android开发的另一个难题。
答案 0 :(得分:10)
好的,我发现了问题 - 主要是PEBKAC。所以这就是:
如果您使用Maven - 就像我一样 - 那么您可以在这里阅读详细信息Automate Android Test Project,这更加令人尴尬 - 两周前我自己写了。
答案 1 :(得分:0)
测试是正确的,应该可行。
请确保Service
和Service.class
引用com.XXX.ws.Service
而非android.app.Service
。