CTS fail issue学习

关于CTS测试,真的是每次碰见都跟初见似的。好像大家永远都是:我也不知道怎么看。
CTS的结果有两份log,一份host_log.txt, 一份device_logcat.txt。
且看host的log:

10-31 18:20:53 I/3204d119376711eb: com.google.android.xts.devicepolicy.DeviceOwnerTest#testUserManagement FAIL
junit.framework.AssertionFailedError: com.google.android.xts.deviceowner.UserManagementTest failed.
at junit.framework.Assert.fail(Assert.java:50)
at junit.framework.Assert.assertTrue(Assert.java:20)
at com.google.android.xts.devicepolicy.DeviceOwnerTest.executeDeviceOwnerTest(DeviceOwnerTest.java:155)
at com.google.android.xts.devicepolicy.DeviceOwnerTest.testUserManagement(DeviceOwnerTest.java:119)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at com.android.tradefed.testtype.DeviceTestResult$1.protect(DeviceTestResult.java:81)
at com.android.tradefed.testtype.DeviceTestResult.runProtected(DeviceTestResult.java:56)
at com.android.tradefed.testtype.DeviceTestResult.run(DeviceTestResult.java:85)
at junit.framework.TestCase.run(TestCase.java:124)
at com.android.tradefed.testtype.DeviceTestCase.run(DeviceTestCase.java:117)
at com.android.xts.tradefed.testtype.JarHostTest$TestRunnable.run(JarHostTest.java:261)
at com.android.tradefed.util.RunUtil$RunnableNotifier.run(RunUtil.java:378)

去翻翻CTS的源码,看看到底测的是什么

 /**
 * Tests that the app is not idle right after it is launched.
 */
public void testAppIsNotIdleAfterBeingLaunched() throws Exception {
    final String previousState = getAppIdleSettings();
    try {
        // Set the app idle time to something large.
        setAppIdleSettings("idle_duration=10000,wallclock_threshold=10000");
        startAndStopTestApp();
        assertFalse(isAppIdle(TEST_APP_PACKAGE));
    } finally {
        setAppIdleSettings(previousState);
    }
}

这个方法是测app是否idle的状态。
首先,assert fail 意思是junit的assert所指示的变量失败,所以查看该变量或者方法是如何所得的即可。

setAppIdleSettings("idle_duration=10000,wallclock_threshold=10000");

private static final String SETTINGS_APP_IDLE_CONSTANTS = "app_idle_constants";
private void setAppIdleSettings(String settingsStr) throws DeviceNotAvailableException {
    mDevice.executeShellCommand(String.format("settings put global %s \"%s\"",
            SETTINGS_APP_IDLE_CONSTANTS, settingsStr));
}

private void startAndStopTestApp() throws DeviceNotAvailableException {
// Launch the app.
mDevice.executeShellCommand(
        String.format("am start -W -a android.intent.action.MAIN -n %s/%s.%s",
                TEST_APP_PACKAGE, TEST_APP_PACKAGE, TEST_APP_CLASS));
// Wait for some time.
sleepUninterrupted(ACTIVITY_LAUNCH_WAIT_MILLIS);
// Launch home.
mDevice.executeShellCommand(
        "am start -W -a android.intent.action.MAIN -c android.intent.category.HOME");
}

private boolean isAppIdle(String appPackage) throws DeviceNotAvailableException {
    String result = mDevice.executeShellCommand(String.format("am get-inactive %s", appPackage));
    return result.contains("Idle=true");
}

显而易见的是,这个测试的绝大多数操作都是通过shell指令去做的。
那么isAppIdle的指令
$ adb shell am get-inactive
主要用于观察你的 App ,确保应用程序恢复正常从待机模式过程中, App 的通知及其背部活动能达到预期结果。
Analysis:
1.Launch the test app for a few hundred millseconds then launch home.
2.Test case expects that after above step test app should not be idle. but true is returned when checked isAppIdle(Test_APP_PACKAGE)
Please check why app is not idle right after it is launched.

最后也没来得及明白整明白根本的解决方案,PL用另一种方法测过了:在非home界面放置一阵开始测试。
未完待续。。。

CSDN:
http://blog.csdn.net/bingducaijun/article/details/51700284
程序园:
http://www.voidcn.com/blog/zhangyongfeiyong/article/p-6143011.html

简书上有一篇讲CTS文章写得还不错:
http://www.jianshu.com/p/3821c1457c2e

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值