1

テスト スイートを実行する Runner クラスを作成しましたが、常に 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();
}

}

私のテストケースファイル。

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);
        }

}

私のマニフェストファイル。

<?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>

私が得ている例外。

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)
4

1 に答える 1