How to allow an exception when building a package?

I have completed the following steps to test my application.

  • I created an Android project.
  • I created a debug signature for my sample application and test application (which needs to be tested)
  • Put sampleapp_debug.apk in the bin folder (where is my workspace)
  • Installed testapp_debug.apk in the emulator.
  • Now I run the project as Android JunitTest.

I get the following error. How to solve this problem.

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) 
+4
source share
4 answers

I used to encounter a similar type of problem. I solved the same thing using the default constructor in Testcode, not a parameterized constructor. The following tutorial was useful for me

See this tutorial

+10
source

I ran into the same error and this solution worked for me:

Do not use public TestTextView (string name), but public TestTextView () as a constructor.

like what W.Elsinga mentions in his comment found here Link

+6
source

Your reference code was old. Just add a default constructor.

 public StartActivityTest() { super(StartActivity.class); } 
+6
source

I think the problem is in the method: android.test.suitebuilder.TestMethod.getAnnotation() .
Try calling the setName() method in the activity constructor.

See: RuntimeException when using ActivityUnitTestCase, but not during ActivityInstrumentationTestCase2

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

0
source

Source: https://habr.com/ru/post/1383807/


All Articles