我是android junit测试的新手,所以请耐心等待......
仅供参考,我正在使用IntelliJ IDEA ..而且我正在运行Mac OSX 10.9(Mavericks)MacBook Pro Mid 2009
所以,我运行我要运行的测试,它构建,然后在它说它运行测试之后,但在模拟器甚至做任何事情之前,它会抛出运行时异常:
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:191)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1701)
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:4335)
at android.app.ActivityThread.access$1500(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
它的测试结果只是“无法创建测试”和“testSuiteConstructionFailed”。
这是测试类和方法:
package com.antechdevelopment.mymedapp.screens.screens;
import android.test.ActivityInstrumentationTestCase2;
import android.test.UiThreadTest;
public class ActivityToTestTest extends ActivityInstrumentationTestCase2<ActivityToTest> {
public ActivityToTestTest(Class<ActivityToTest> activityClass) {
super(activityClass);
}
@Override
protected void setUp() throws Exception {
super.setUp();
setActivityInitialTouchMode(false);
/*Other prerequisite code to be executed*/
}
@UiThreadTest //This allows me to interact with the views on the app's main thread...
public void testFoo() {
/*Code to test with...*/
}
}
我的测试模块的AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.antechdevelopment.mymedapp.tests"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<application>
<uses-library android:name="android.test.runner"/>
</application>
<instrumentation android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.antechdevelopment.mymedapp"
android:label="Tests for com.antechdevelopment.mymedapp"/>
</manifest>
谢谢, Joshua K
答案 0 :(得分:0)
我发现这是一种使用Android Studio的方法。我猜这同样适用于IntelliJ IDEA。请注意,我是Android开发和Java的新手。
该方法同时使用Android studio和adb工具。
最后两个步骤与the android developer guide的说明中的最后一步相同。