51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 2643|回复: 0
打印 上一主题 下一主题

[Appium] 一则CTS测试错误分析

[复制链接]
  • TA的每日心情
    无聊
    2024-7-12 13:16
  • 签到天数: 1 天

    连续签到: 1 天

    [LV.1]测试小兵

    跳转到指定楼层
    1#
    发表于 2019-4-3 15:19:12 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
    CTS测试传感器发现失败,具体错误是PackageManager找不到,SensorManager确能找到

    cts_host > start --plan CTS -t android.app.cts.SystemFeaturesTest#testSensorFeatures

    start test android.app.cts.SystemFeaturesTest#testSensorFeatures

    ==============================================================

    Test package: android.app

    android.app.cts.SystemFeaturesTest#testSensorFeatures...(fail)

    junit.framework.AssertionFailedError: PackageManager#hasSystemFeature(android.hardware.sensor.accelerometer) returns false but SensorManager#getSensorList(1) shows sensors [3-axis Accelerometer] expected:<false> but was:<true> at android.app.cts.SystemFeaturesTest.assertFeatureForSensor(SystemFeaturesTest.java:295)

    at android.app.cts.SystemFeaturesTest.assertFeatureForSensor(SystemFeaturesTest.java:295)

    at android.app.cts.SystemFeaturesTest.testSensorFeatures(SystemFeaturesTest.java:213)

    at java.lang.reflect.Method.invokeNative(Native Method)

    at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:204)

    at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:194)

    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)

    at android.app.cts.SystemFeaturesTest.assertFeatureForSensor(SystemFeaturesTest.java:295)

    at android.app.cts.SystemFeaturesTest.testSensorFeatures(SystemFeaturesTest.java:213)

    at java.lang.reflect.Method.invokeNative(Native Method)

    at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:204)

    at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:194)

    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)



    ==============================================================

    Time: 5177129.236s



    cts_host >



    PackageManager找不到传感器,说明错误出在PM身上。

    查看CTS测试代码,如红色所示,当expectedFeature为FEATURE_SENSOR_ACCELEROMETER时,返回错误。



        private void assertFeatureForSensor(Set<String> featuresLeft, String expectedFeature,

                int expectedSensorType) {

            assertTrue("Features left " + featuresLeft + " to check did not include "

                    + expectedFeature, featuresLeft.remove(expectedFeature));



            boolean hasSensorFeature = mPackageManager.hasSystemFeature(expectedFeature);



            List<Sensor> sensors = mSensorManager.getSensorList(expectedSensorType);

            List<String> sensorNames = new ArrayList<String>(sensors.size());

            for (Sensor sensor : sensors) {

                sensorNames.add(sensor.getName());

            }

            boolean hasSensorType = !sensors.isEmpty();



            String message = "PackageManager#hasSystemFeature(" + expectedFeature + ") returns "

                    + hasSensorFeature

                    + " but SensorManager#getSensorList(" + expectedSensorType + ") shows sensors "

                    + sensorNames;



            assertEquals(message, hasSensorFeature, hasSensorType);

        }



    这个字串系统中是有的,但是hasSystemFeature需要检查权限,需要将frameworks/base/data/etc/android.hardware.sensor.accelerometer.xml文件添加进目标板。

    frameworks/base/core/java/android/content/pm/PackageManager.java:727:   

    public static final String FEATURE_SENSOR_ACCELEROMETER = "android.hardware.sensor.accelerometer";



    最终在mk中添加以下内容解决问题。

    frameworks/base/data/etc/android.hardware.sensor.accelerometer.xml:system/etc/permissions/android.hardware.sensor.accelerometer.xml \
    分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    收藏收藏
    回复

    使用道具 举报

    本版积分规则

    关闭

    站长推荐上一条 /1 下一条

    小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

    GMT+8, 2024-11-15 01:10 , Processed in 0.069184 second(s), 23 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

    快速回复 返回顶部 返回列表