SuperAPI AI 工具集

mobile-app-testing

测试与质量

查看项目

更新于 10-15 03:01

技能介绍

用途

本技能用于为移动应用实施全面的测试策略,覆盖单元测试、UI 自动化与性能测试。适用于搭建测试基础设施、编写端到端(E2E)测试、制定测试标准,或在遇到测试相关问题时参考。

主要能力

资料以测试金字塔的形式给出分层测试建议:

层级 工具 覆盖率
单元测试 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);
  });
});

React Native(Detox)E2E 测试示例:

// E2E test (Detox)
describe('Login flow', () => {
  beforeEach(async () => {
    await device.reloadReactNative();
  });

  it('should login successfully', async () => {
    await element(by.id('email-input')).typeText('user@example.com');
    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("user@example.com")
    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("user@example.com"))
    onView(withId(R.id.password)).perform(typeText("password123"))
    onView(withId(R.id.loginButton)).perform(click())
    onView(withId(R.id.dashboard)).check(matches(isDisplayed()))
}

最佳实践

资料列出的最佳实践包括:优先测试业务逻辑(单元测试);模拟(Mock)外部依赖;同时测试成功路径与失败路径;自动化关键用户流程;保持代码覆盖率大于 80%;定期在真实设备上测试。

应避免的做法

资料列出的应避免事项包括:测试实现细节;硬编码测试数据;测试之间相互依赖;跳过错误场景测试。

限制

资料未提供该技能的安装命令、具体运行方式、支持的平台版本、性能测试的具体工具与指标,以及收费或授权信息,这些内容暂未提供。