套件构建过程中出现异常如何解决?

发布于 2024-12-18 20:32:10 字数 2498 浏览 2 评论 0原文

我已按照以下步骤来测试我的应用程序。

  1. 我已经创建了 Android 项目。
  2. 我已经为我的示例应用程序和测试应用程序(需要测试)创建了调试签名
  3. 将sampleapp_debug.apk放在bin文件夹中(我的工作区在那里)
  4. 在模拟器中安装了testapp_debug.apk。
  5. 现在我正在将项目作为 Android JunitTest 运行。

我收到以下错误..如何解决这个问题..

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.NullPointerException: Method name must not be null.
at java.lang.ClassCache.findMethodByName(ClassCache.java:297)
at java.lang.Class.getMethod(Class.java:985)
at android.test.suitebuilder.TestMethod.getAnnotation(TestMethod.java:60)
at android.test.suitebuilder.annotation.HasMethodAnnotation.apply(HasMethodAnnotation.java:39)
at android.test.suitebuilder.annotation.HasMethodAnnotation.apply(HasMethodAnnotation.java:30)
at com.android.internal.util.Predicates$OrPredicate.apply(Predicates.java:106)
at android.test.suitebuilder.annotation.HasAnnotation.apply(HasAnnotation.java:42)
at android.test.suitebuilder.annotation.HasAnnotation.apply(HasAnnotation.java:31)
at com.android.internal.util.Predicates$NotPredicate.apply(Predicates.java:122)
at android.test.suitebuilder.TestSuiteBuilder.satisfiesAllPredicates(TestSuiteBuilder.java:254)
at android.test.suitebuilder.TestSuiteBuilder.build(TestSuiteBuilder.java:190)
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)

I have followed the below steps to test my app.

  1. I have created Android Project.
  2. I have created the debug signature for my sample app and test app(which need to be tested)
  3. Place the sampleapp_debug.apk in the bin folder (where my workspace is there)
  4. Installed the testapp_debug.apk in the emulator.
  5. Now i am running the project as a Android JunitTest.

I am getting the below error.. How to resolve this..

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.NullPointerException: Method name must not be null.
at java.lang.ClassCache.findMethodByName(ClassCache.java:297)
at java.lang.Class.getMethod(Class.java:985)
at android.test.suitebuilder.TestMethod.getAnnotation(TestMethod.java:60)
at android.test.suitebuilder.annotation.HasMethodAnnotation.apply(HasMethodAnnotation.java:39)
at android.test.suitebuilder.annotation.HasMethodAnnotation.apply(HasMethodAnnotation.java:30)
at com.android.internal.util.Predicates$OrPredicate.apply(Predicates.java:106)
at android.test.suitebuilder.annotation.HasAnnotation.apply(HasAnnotation.java:42)
at android.test.suitebuilder.annotation.HasAnnotation.apply(HasAnnotation.java:31)
at com.android.internal.util.Predicates$NotPredicate.apply(Predicates.java:122)
at android.test.suitebuilder.TestSuiteBuilder.satisfiesAllPredicates(TestSuiteBuilder.java:254)
at android.test.suitebuilder.TestSuiteBuilder.build(TestSuiteBuilder.java:190)
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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

故人的歌 2024-12-25 20:32:10

我以前遇到过类似的问题。我通过在 Testcode 中使用默认构造函数而不是参数化构造函数解决了同样的问题。以下教程对我很有用

查看本教程

I faced similar type of problem before. I resolved the same by using default constructor in Testcode rather than parametrized constructor. The following tutorial was useful for me

See this tutorial

枕头说它不想醒 2024-12-25 20:32:10

我遇到了同样的错误,这个解决方案对我有用:

不要使用 public TestTextView(String name) 而是 public TestTextView()
作为构造函数。

正如 W.Elsinga 在他的评论中提到的那样 链接

I encounter the same error and this solution worked for me:

Do not use public TestTextView(String name) but public TestTextView()
as constructor.

as what W.Elsinga mention on his comment found here Link

無心 2024-12-25 20:32:10

您引用的代码太旧了。
只需添加默认构造函数即可。

public StartActivityTest() {
    super(StartActivity.class);
}

Your referenced code was way old.
Just add default constructor.

public StartActivityTest() {
    super(StartActivity.class);
}
女皇必胜 2024-12-25 20:32:10

我认为问题出在方法:android.test.suitebuilder.TestMethod.getAnnotation()
尝试在活动的构造函数中调用方法setName()

请参阅:使用 ActivityUnitTestCase 时出现 RuntimeException,但在 ActivityInstrumentationTestCase2 时出现 RuntimeException

异常也是由 android.test.suitebuilder.TestMethod.getAnnotation() 引起的。

I think the problem at method: android.test.suitebuilder.TestMethod.getAnnotation().
Try to call the method setName() at constructor of the activity.

See: RuntimeException while using ActivityUnitTestCase, but not while ActivityInstrumentationTestCase2

The exception is caused by android.test.suitebuilder.TestMethod.getAnnotation(), too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文