我有一些要求,我应该随时在我的设备上运行测试项目,而无需将其连接到系统并通过 eclipse 运行。
我添加了一些intent-filter
以AndroidManifest.xml
使测试项目在启动器上可见,但是,它从未成功运行并且无法找到目标活动类
同时,如果我将设备连接到系统,并从 eclipse perform Run As Android Junit
,它运行成功,没有任何异常。那么这里有什么问题呢?我错过了一些概念吗?
以下是AndroidManifest.xml
我的测试应用程序
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.org.search.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" android:targetSdkVersion="18"/>
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.third.party.packageName" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<uses-library android:name="android.test.runner" />
<activity android:name="com.org.search.test.MyTestClass">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
这是异常日志
java.lang.ExceptionInInitializerError
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1130)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2183)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2316)
at android.app.ActivityThread.access$600(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1298)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:5225)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:741)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException:
com.third.party.packageName.SearchActivity
at com.expedia.search.test.ExpediaHotelsScraper.<clinit>(ExpediaHotelsScraper.java:35)
... 15 more
Caused by: java.lang.ClassNotFoundException: com.third.party.packageName.SearchActivity
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:204)
at java.lang.Class.forName(Class.java:169)
at com.org.search.test.MyTestClass.<clinit>(MyTestClass.java:32)
... 15 more
Caused by: java.lang.NoClassDefFoundError: com/third/party/packageName/activity/SearchActivity
... 19 more
Caused by: java.lang.ClassNotFoundException: Didn't find class
"com.third.party.packageName.SearchActivity" on path:
DexPathList[[zip file "/system/framework/android.test.runner.jar",
zip file "/data/app/com.org.search.test-1.apk"],
nativeLibraryDirectories=[/data/app-lib/com.org.search.test-1,
/vendor/lib, /system/lib]]
还有测试类代码MyTestClass.java
public class MyTestClass extends ActivityInstrumentationTestCase2 {
private static final String LAUNCH_ACTIVITY_NAME =
"com.third.party.packageName.activity.SearchActivity";
private Solo solo;
private static Class<?> splashActivityClass;
static {
try {
splashActivityClass = Class.forName(LAUNCH_ACTIVITY_NAME);
}
catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
public MyTestClass() throws ClassNotFoundException {
super(splashActivityClass);
}
@Override
protected void setUp() throws Exception {
solo = new Solo(getInstrumentation(), getActivity());
}
public void testAllCountries() {
//my test goes here
}
我是android自动化的新手。如果我尝试一些不可行的事情,请帮助我理解这个概念。