关于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界面放置一阵开始测试。
未完待续。。。
优快云:
http://blog.youkuaiyun.com/bingducaijun/article/details/51700284
程序园:
http://www.voidcn.com/blog/zhangyongfeiyong/article/p-6143011.html
简书上有一篇讲CTS文章写得还不错:
http://www.jianshu.com/p/3821c1457c2e