0

我目前正在为我们自己的设备处理一些 CTS 问题。我想到,如果我们可以仅从 Eclipse 运行单个 CTS 测试用例,那将非常有助于调试 CTS 问题。例如,我创建了一个带有清单文件的 Android 测试项目:

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="android.content.pm.cts"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="15" />

    <instrumentation
        android:name="android.test.InstrumentationTestRunner"
        android:targetPackage="android.content.pm" />

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

</manifest>

和源代码:

 package android.content.pm.cts;

import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.ResolveInfo.DisplayNameComparator;
import android.test.AndroidTestCase;

public class ResolveInfo_DisplayNameComparatorTest extends AndroidTestCase {
    private static final String MAIN_ACTION_NAME = "android.intent.action.MAIN";
    private static final String SERVICE_NAME = "android.content.pm.cts.activity.PMTEST_SERVICE";


    public void testDisplayNameComparator() {
        PackageManager pm = getContext().getPackageManager();
        DisplayNameComparator dnc = new DisplayNameComparator(pm);

        Intent intent = new Intent(MAIN_ACTION_NAME);
        ResolveInfo activityInfo = pm.resolveActivity(intent, 0);

        intent = new Intent(SERVICE_NAME);
        ResolveInfo serviceInfo = pm.resolveService(intent, PackageManager.GET_RESOLVED_FILTER);

        assertTrue(dnc.compare(activityInfo, serviceInfo) < 0);
        assertTrue(dnc.compare(activityInfo, activityInfo) == 0);
        assertTrue(dnc.compare(serviceInfo, activityInfo) > 0);
    }
}

当我右键单击项目并选择“run as android junit test”时,它只会报告:测试运行失败:无法找到检测目标包:android.content.pm

我知道我可能从一开始就完全错了。那么有人可以为我指出正确的出路吗?非常感谢!

4

1 回答 1

0

The error you are seeing is because the android OS cannot find an application installed with the package "android.content.pm" and eclipse does not know about the project in order to install it for you, install the application you want to test (and check its package is in fact android.content.pm which it probably isn't because that is a system package and you will not be able to instrument against that because your debug signature is not the same)

于 2013-03-15T09:12:45.113 回答