关于 mobile-app-testing
面向使用 React Native、iOS 和 Android 的团队的移动应用测试技能,介绍测试金字塔,并提供单元、集成和端到端测试示例。
主要功能
- 01测试金字塔指南
- 02React Native 的 Jest 与 Detox 示例
- 03iOS XCTest 示例
- 04Android Espresso 示例
- 05覆盖率与失败路径测试建议
适用场景
- 01规划单元、集成和端到端测试覆盖
- 02测试移动应用登录等关键流程
- 03检查业务逻辑与错误处理
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ secondsky/ claude-skills --skill mobile-app-testing安装后在 Claude Code 中输入/mobile-app-testing确认已加载。
详细介绍
移动应用测试
为移动应用实施全面的测试策略。
测试金字塔
| 级别 | 工具 | 覆盖率 |
|---|---|---|
| 单元测试 | Jest, XCTest, JUnit | 70% |
| 集成测试 | Detox, Espresso | 20% |
| 端到端测试 | Appium, Detox | 10% |
React Native(Jest + Detox)
// Unit test
describe('CartService', () => {
it('calculates total correctly', () => {
const cart = new CartService();
cart.addItem({ price: 10, quantity: 2 });
expect(cart.getTotal()).toBe(20);
});
});
// E2E test (Detox)
describe('Login flow', () => {
beforeEach(async () => {
await device.reloadReactNative();
});
it('should login successfully', async () => {
await element(by.id('email-input')).typeText('[email protected]');
await element(by.id('password-input')).typeText('password123');
await element(by.id('login-button')).tap();
await expect(element(by.id('dashboard'))).toBeVisible();
});
});
iOS(XCTest)
func testLoginSuccess() {
let app = XCUIApplication()
app.launch()
app.textFields["email"].tap()
app.textFields["email"].typeText("[email protected]")
app.secureTextFields["password"].typeText("password123")
app.buttons["Login"].tap()
XCTAssertTrue(app.staticTexts["Welcome"].exists)
}
Android(Espresso)
@Test
fun loginSuccess() {
onView(withId(R.id.email)).perform(typeText("[email protected]"))
onView(withId(R.id.password)).perform(typeText("password123"))
onView(withId(R.id.loginButton)).perform(click())
onView(withId(R.id.dashboard)).check(matches(isDisplayed()))
}
最佳实践
- 优先测试业务逻辑(单元测试)
- 模拟外部依赖
- 测试成功和失败路径
- 自动化关键用户流程
- 将代码覆盖率保持在 80% 以上
- 定期在真实设备上测试
避免
- 测试实现细节
- 使用硬编码的测试数据
- 编写相互依赖的测试
- 跳过错误场景测试
评论
支持 Markdown