Skip to content

Commit

Permalink
Add function to clear data between runs
Browse files Browse the repository at this point in the history
  • Loading branch information
keyboardsurfer committed Aug 30, 2024
1 parent 26651e0 commit 09770d8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,18 @@

package com.example.macrobenchmark.baselineprofile

const val TARGET_PACKAGE = "com.example.macrobenchmark.target"
import androidx.benchmark.macro.MacrobenchmarkScope
import androidx.test.uiautomator.UiDevice

const val TARGET_PACKAGE = "com.example.macrobenchmark.target"

/**
* Clears the application data for the package specified in the [MacrobenchmarkScope].
* @param scope The [MacrobenchmarkScope] providing information about the benchmark,
* including the package name of the app under test.
*/
fun UiDevice.clearData(scope: MacrobenchmarkScope) {
val command = "pm clear $scope.packageName"
val output = executeShellCommand(command)
// Assert.assertEquals("Success", output)
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class LoginBaselineProfileGenerator {
maxIterations = 15,
stableIterations = 3
) {
device.clearData(this)
startActivityAndWait(Intent("$packageName.LOGIN_ACTIVITY"))
device.findObject(By.res("userName")).text = "user"
device.findObject(By.res("password")).text = "password"
Expand Down

0 comments on commit 09770d8

Please sign in to comment.