1

I have written Runner class to execute an test suite but i am constantly getting java.lang.RuntimeException: Exception during suite construction.Method name could not be null.

import junit.framework.TestSuite;
import android.test.InstrumentationTestRunner;
import android.test.InstrumentationTestSuite;

public class Runner extends InstrumentationTestRunner {


public Runner() {
    super();
}



@Override
public TestSuite getAllTests() {
    InstrumentationTestSuite suite = new InstrumentationTestSuite(this);
    suite.addTest(new AndroidTest());
    return suite;
}

@Override
public ClassLoader getLoader() {
    return Runner.class.getClassLoader();
}

}

My test case file.

import junit.framework.Assert;
import android.test.ActivityTestCase;

public class AndroidTest extends AndroidTestCase{

     @Override
        protected void setUp() throws Exception {
            // TODO Auto-generated method stub
            super.setUp();
        }

     String nuber;
     public AndroidTest(String number1) {
         System.out.println("paramertized");
         this.nuber=number1;

    }
     public AndroidTest() {
         super();
         System.out.println("default");
    }




    public void testSomething() throws Throwable {
        System.out.println(nuber);
           Assert.assertTrue(1 + 1 == 2);
        }

        public void testSomethingElse() throws Throwable {
           Assert.assertTrue(1 + 1 == 3);
        }

}

My manifestfile.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="jp.co.rakuten.sdt.sampleapp.test"
    android:versionCode="1"
    android:versionName="1.0" >
<uses-permission android:name="android.permission.RUN_INSTRUMENTATION" />
    <uses-sdk android:minSdkVersion="9" />

    <instrumentation
        android:name="com.sampleapp.test.Runner"
        android:targetPackage="com.sampleapp" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <uses-library android:name="android.test.runner" />
    </application>

</manifest>

exception i am getting.

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:529)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1448)
Caused by: java.lang.NullPointerException: Method name must not be null.
at java.lang.ClassCache.findMethodByName(ClassCache.java:238)
at java.lang.Class.getMethod(Class.java:962)
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:3246)
at android.app.ActivityThread.access$2200(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:969)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Piyush
  • 1,973
  • 1
  • 19
  • 30

1 Answers1

0

Ok, so I can reproduce your problem.

By removing the public AndroidTest(String) constructor and setting a value to the String variable nuber I can get the tests to run.

String nuber ="";
/*
public AndroidTest(String number1) {
    super();
    System.out.println("paramertized");
    this.nuber=number1;

}
*/
public AndroidTest() {
    super();
    System.out.println("default");
}

A similar question posted here on SO

Community
  • 1
  • 1
mach
  • 8,315
  • 3
  • 33
  • 51
  • Hmm, as a test, try removing the parameterized constructor. – mach Apr 16 '13 at 13:49
  • Pretty sure it's the parameterized constructor thats been giving you grief. – mach Apr 17 '13 at 17:24
  • i have also removed the paramiterized constructor even then i am not able to run the suite same problem is coming any other changes that you have made(in manifest or somewhere else). – Piyush Apr 18 '13 at 08:43
  • Initialized String nuber =""; or you get a null pointer exception. – mach Apr 18 '13 at 09:41
  • Thanks for the response but i am still getting same problem after all the changes told by you. – Piyush Apr 18 '13 at 09:52
  • when i remove this line from the code // suite.addTest(new AndroidTest()); only then my code is running , but then it has no test cases to run. – Piyush Apr 18 '13 at 10:03