Skip to content

Commit 74ef597

Browse files
authored
Merge pull request #786 from android/st/topic-screen-benchmark
Added scroll test for topic list
2 parents 890c0f5 + 6f06704 commit 74ef597

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright 2023 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.samples.apps.nowinandroid.interests
18+
19+
import androidx.benchmark.macro.CompilationMode
20+
import androidx.benchmark.macro.FrameTimingMetric
21+
import androidx.benchmark.macro.StartupMode
22+
import androidx.benchmark.macro.junit4.MacrobenchmarkRule
23+
import androidx.test.ext.junit.runners.AndroidJUnit4
24+
import androidx.test.uiautomator.By
25+
import com.google.samples.apps.nowinandroid.PACKAGE_NAME
26+
import com.google.samples.apps.nowinandroid.allowNotifications
27+
import org.junit.Rule
28+
import org.junit.Test
29+
import org.junit.runner.RunWith
30+
31+
@RunWith(AndroidJUnit4::class)
32+
class ScrollTopicListBenchmark {
33+
@get:Rule
34+
val benchmarkRule = MacrobenchmarkRule()
35+
36+
@Test
37+
fun benchmarkStateChangeCompilationBaselineProfile() =
38+
benchmarkStateChange(CompilationMode.Partial())
39+
40+
private fun benchmarkStateChange(compilationMode: CompilationMode) =
41+
benchmarkRule.measureRepeated(
42+
packageName = PACKAGE_NAME,
43+
metrics = listOf(FrameTimingMetric()),
44+
compilationMode = compilationMode,
45+
iterations = 10,
46+
startupMode = StartupMode.WARM,
47+
setupBlock = {
48+
// Start the app
49+
pressHome()
50+
startActivityAndWait()
51+
allowNotifications()
52+
// Navigate to interests screen
53+
device.findObject(By.text("Interests")).click()
54+
device.waitForIdle()
55+
},
56+
) {
57+
interestsWaitForTopics()
58+
repeat(3) {
59+
interestsScrollTopicsDownUp()
60+
}
61+
}
62+
}

0 commit comments

Comments
 (0)