创建基准配置文件时清除应用数据

3

我正在尝试为我的Android应用程序创建一些基线配置文件,这些配置文件比startActivityAndWait()更有意义。

我的应用程序从未初始化状态开始,但是一旦用户选择了目的地,它就会存储在DataStore首选项中,然后您将不再看到初始屏幕。

这意味着运行BaselineProfileRule的后续迭代失败,因为最初的按钮等已不再适用。

是否有一种方法可以在BaselineProfile测试中清除测试运行之间的应用程序数据?我尝试在测试中添加InstrumentationRegistry.getInstrumentation().uiAutomation.executeShellCommand("adb shell pm clear *packageName*"),但似乎没有任何效果。

我还尝试将testInstrumentationRunnerArguments clearPackageData: 'true'添加到基准build.gradle中,但这也没有效果。


据报道 - 让我们看看这是否是那些需要数年才能解决的问题之一... https://issuetracker.google.com/issues/259388454 - slott
1个回答

3
我一直在使用的解决方法是...
fun MacrobenchmarkScope.isFirstIteration() = iteration == 0

然后,在设置块内:

if (isFirstIteration()) {
    pressHome()
    startActivityAndWait()
    //Login
    killProcess()
}

第一次迭代应该是 iteration == 1 - undefined
哦,等等,BaselineProfileRule 是1,MacrobenchmarkRule 是0。 - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接