Application unit test reports TestMethod null pointer exception

2391 단어
When writing the Application unit test, a null pointer error occurred.
code show as below:
public class MyApplicationTests extends ApplicationTestCase<MyApplication> {

         public MyApplicationTests(Class<MyApplication> applicationClass) {
		super(applicationClass);
		// TODO Auto-generated constructor stub
	}

	public void testApp() {
	}
}

The exception reported is as follows:
java.lang.RuntimeException: Exception during suite construction
at android.test.suitebuilder.TestSuiteBuilder$FailedToCreateTests.testSuiteConstructionFailed(TestSuiteBuilder.java:238)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1619)
Caused by: java.lang.NullPointerException
at android.test.suitebuilder.TestMethod.<init>(TestMethod.java:47)
at android.test.suitebuilder.TestSuiteBuilder.build(TestSuiteBuilder.java:189)
at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:379)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4239)
at android.app.ActivityThread.access$1400(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1298)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4918)
at java.lang.reflect.Method.invokeNative(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
at dalvik.system.NativeStart.main(Native Method)


 
Later, I changed the code to the following, and the test passed:
public class MyApplicationTests extends ApplicationTestCase<MyApplication> {

	public MyApplicationTests() {
		super(MyApplication.class);
	}

	public void testApp() {

	}

}


I don't know the specific reason. If you know why, I hope you can leave a message and share it together! Hehe, thank you!
 

좋은 웹페이지 즐겨찾기