4

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)
ChanGan
  • 4,254
  • 11
  • 74
  • 135

4 Answers4

10

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

Sean O'Toole
  • 4,304
  • 6
  • 35
  • 43
Sunil Kumar Sahoo
  • 53,011
  • 55
  • 178
  • 243
  • I am having only .apk. Do i need to create Andorid Project and Android Test Project both? or the procedure which i mention is correct? please correct if i am wrong on this.. – ChanGan Nov 30 '11 at 08:25
6

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

FritzB
  • 335
  • 3
  • 14
6

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

public StartActivityTest() {
    super(StartActivity.class);
}
Youngjae
  • 24,352
  • 18
  • 113
  • 198
0

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.

Community
  • 1
  • 1
Huyen
  • 21
  • 2