Skip to content

Commit 4b8d0a0

Browse files
committed
Add monkey test plan, logs, and improve UI tests
Added a test plan for emulator monkey testing and included log files for test runs. Enhanced ReaderInstrumentedTest with menu and night mode toggle UI tests, and improved swipe gesture reliability. Added content description to night mode switch for better testability.
1 parent 95a8c8b commit 4b8d0a0

File tree

5 files changed

+1867
-5
lines changed

5 files changed

+1867
-5
lines changed

TODO/monkey_emulator.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Emulator Monkey Test Plan
2+
3+
- [x] Configuration
4+
- Device: `emulator-5554` (Pixel 9 Pro)
5+
- Package: `com.xuyutech.hongbaoshu`
6+
- Events: 10,000
7+
- Throttle: 50ms
8+
- Log File: `monkey_logs/monkey_emulator.log`
9+
- [x] Execution
10+
- [x] Run Command (`adb -s emulator-5554 shell monkey...`)
11+
- [x] Monitor for crashes (Result: System Crash/ANR at event 5)
12+
- [x] Retry Test (Started: monkey_logs/monkey_emulator_retry.log)
13+
- [x] Reporting
14+
- [x] Check log for "Monkey finished" (Confirmed)
15+
- [x] Check for exceptions/ANRs (None found)

app/src/androidTest/java/com/xuyutech/hongbaoshu/ReaderInstrumentedTest.kt

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ class ReaderInstrumentedTest {
4646
// 执行右滑手势返回 (从左边缘向右滑动)
4747
composeTestRule.onRoot().performTouchInput {
4848
swipe(
49-
start = androidx.compose.ui.geometry.Offset(width * 0.1f, centerY),
49+
start = androidx.compose.ui.geometry.Offset(width * 0.2f, centerY), // Avoid system edge (0.1f -> 0.2f)
5050
end = androidx.compose.ui.geometry.Offset(width * 0.9f, centerY),
51-
durationMillis = 300
51+
durationMillis = 500 // Slower swipe
5252
)
5353
}
5454

@@ -60,7 +60,52 @@ class ReaderInstrumentedTest {
6060
composeTestRule.onNodeWithContentDescription("封面").assertIsDisplayed()
6161
}
6262

63-
// 注意: 移除了菜单相关测试,因为双击手势在 CI 环境的模拟器上不稳定
64-
// 菜单功能(打开设置/目录)在真机和本地测试中工作正常
65-
// 这是测试环境的限制,不影响实际应用功能
63+
@Test
64+
fun openMenu_verifyDisplay() {
65+
// 进入阅读界面
66+
composeTestRule.onNodeWithContentDescription("封面").performClick()
67+
composeTestRule.waitForIdle()
68+
Thread.sleep(2000)
69+
70+
// 尝试点击中间区域以关闭可能存在的引导层
71+
composeTestRule.onRoot().performTouchInput { click() }
72+
composeTestRule.waitForIdle()
73+
Thread.sleep(1000)
74+
75+
// 双击顶部区域唤出菜单
76+
composeTestRule.onRoot().performTouchInput {
77+
// slightly lower to ensure hit
78+
val topArea = androidx.compose.ui.geometry.Offset(centerX, height * 0.15f)
79+
doubleClick(topArea)
80+
}
81+
82+
composeTestRule.waitForIdle()
83+
84+
// 验证菜单标题显示
85+
composeTestRule.onNodeWithText("阅读设置").assertIsDisplayed()
86+
}
87+
88+
@Test
89+
fun toggleNightMode_changesState() {
90+
// 进入阅读界面
91+
composeTestRule.onNodeWithContentDescription("封面").performClick()
92+
composeTestRule.waitForIdle()
93+
Thread.sleep(2000)
94+
95+
// 打开菜单
96+
composeTestRule.onRoot().performTouchInput {
97+
doubleClick(androidx.compose.ui.geometry.Offset(centerX, height * 0.15f))
98+
}
99+
composeTestRule.waitForIdle()
100+
101+
// 验证夜间模式开关存在并关闭
102+
composeTestRule.onNodeWithContentDescription("夜间模式开关").assertIsOff()
103+
104+
// 点击切换
105+
composeTestRule.onNodeWithContentDescription("夜间模式开关").performClick()
106+
composeTestRule.waitForIdle()
107+
108+
// 验证开关变为打开状态
109+
composeTestRule.onNodeWithContentDescription("夜间模式开关").assertIsOn()
110+
}
66111
}

app/src/main/java/com/xuyutech/hongbaoshu/reader/ReaderScreen.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import androidx.compose.material.icons.filled.Settings
88
import androidx.compose.material.icons.filled.Info
99

1010
import androidx.compose.ui.draw.scale
11+
import androidx.compose.ui.semantics.contentDescription
12+
import androidx.compose.ui.semantics.semantics
1113

1214

1315
import androidx.compose.animation.AnimatedVisibility
@@ -859,6 +861,7 @@ private fun MenuPanel(
859861
)
860862
}
861863
Switch(
864+
modifier = Modifier.semantics { contentDescription = "夜间模式开关" },
862865
checked = isNightMode,
863866
onCheckedChange = { onToggleNightMode() }
864867
)

0 commit comments

Comments
 (0)