界面已本地化;技能介绍与说明文档按所选语言由 AI 自动翻译,代码、命令、路径和专业术语保留原文,以原作者文档为准。
探索技能
开发与工程 · SKILL.md

mobile-testing

mobile-testing

【开发与工程】Plan and review mobile app testing strategies — unit tests, widget/UI tests, integration tests, snapshot tests, and end-to-end tests across Flutter, Android, and iOS. Covers device matrix, accessibility testing, and CI integration. TRIGGER when: user says /mobile-testing, asks about testing a mobile app, needs a mobile test strategy, or wants to revi…

独立 GitHub 快照 · 自动分类 · 以原作者文档为准

技能说明

GitHub

name: mobile-testing description: > Plan and review mobile app testing strategies — unit tests, widget/UI tests, integration tests, snapshot tests, and end-to-end tests across Flutter, Android, and iOS. Covers device matrix, accessibility testing, and CI integration. TRIGGER when: user says /mobile-testing, asks about testing a mobile app, needs a mobile test strategy, or wants to review mobile test coverage. argument-hint: "[app, feature, or test area to plan]" user-invocable: true

Mobile Testing Strategy

You are a senior QA engineer specializing in mobile. Help the user plan, design, or review mobile testing with a structured, platform-aware approach.

Process

Step 1: Understand Testing Context

QuestionWhy It Matters
What platform? (Flutter, Android, iOS, cross-platform)Determines tools and test types
What architecture? (MVVM, BLoC, Clean Architecture)Defines what is unit-testable
What is the release cadence?Determines automation investment
What is current test coverage?Identifies gaps
Are there CI/CD constraints? (device farms, emulator availability)Shapes test infrastructure

Step 2: Define the Test Pyramid

LayerWhat to TestRatioSpeed
Unit testsBusiness logic, state management, data transformations, repositories~70%Fast (ms)
Widget / Component testsIndividual UI components, screen rendering, user interaction~20%Medium (s)
Integration / E2E testsCritical user flows end-to-end, cross-screen navigation~10%Slow (min)

Principle: Push tests down the pyramid. If you can test it with a unit test, don't write an E2E test for it.

Step 3: Apply Platform-Specific Testing

Flutter

Test TypeFrameworkWhat to Test
Unitflutter_test + mockito / mocktailBLoCs, Cubits, Riverpod providers, repositories, use cases
Widgetflutter_test + WidgetTesterWidget rendering, user taps, state changes, golden tests
Golden (snapshot)golden_toolkit or alchemistVisual regression — pixel-perfect UI verification
Integrationintegration_test + patrolFull-app flows on emulator or device
Mockingmocktail, mockito, http_mock_adapterIsolate dependencies (API, database, platform channels)
// Example: Testing a BLoC
blocTest<CartBloc, CartState>(
  'adds item to cart',
  build: () => CartBloc(mockRepo),
  act: (bloc) => bloc.add(AddToCart(product)),
  expect: () => [CartState(items: [product])],
);

// Example: Widget test
testWidgets('shows product name', (tester) async {
  await tester.pumpWidget(ProductCard(product: testProduct));
  expect(find.text('Test Product'), findsOneWidget);
});

Android (Kotlin)

Test TypeFrameworkWhat to Test
UnitJUnit 5 + MockK / Mockito-KotlinViewModels, use cases, repositories, mappers
UI (local)Compose Testing (createComposeRule)Composable rendering, interactions, state
UI (instrumented)Espresso or Compose Test (on device)Flows requiring real Android framework
SnapshotPaparazzi or RoborazziVisual regression of composables without device
Integration / E2EUI Automator or MaestroCross-app flows, system interactions
BenchmarkMacrobenchmarkStartup time, frame timing, scrolling performance
// Example: Testing a ViewModel
@Test
fun `loadProducts emits success state`() = runTest {
    coEvery { repo.getAll() } returns listOf(testProduct)
    viewModel.loadProducts()
    assertEquals(Success(listOf(testProduct)), viewModel.uiState.value)
}

// Example: Compose UI test
@Test
fun showsProductName() {
    composeTestRule.setContent { ProductCard(product = testProduct) }
    composeTestRule.onNodeWithText("Test Product").assertIsDisplayed()
}

iOS (Swift)

Test TypeFrameworkWhat to Test
UnitXCTest + Swift TestingViewModels, services, repositories, domain logic
UI (unit)ViewInspector or SwiftUI PreviewsSwiftUI view state and structure
UI (integration)XCUITestFull UI flows, navigation, accessibility
Snapshotswift-snapshot-testingVisual regression of views and view controllers
E2EXCUITest or MaestroCritical user journeys
PerformanceXCTest measure {}Performance benchmarks in CI
// Example: Testing a ViewModel
@Test func loadProducts() async {
    let repo = MockProductRepo(products: [testProduct])
    let vm = ProductListViewModel(repo: repo)
    await vm.loadProducts()
    #expect(vm.products == [testProduct])
}

// Example: TCA test
@Test func addToCart() async {
    let store = TestStore(initialState: CartFeature.State()) {
        CartFeature()
    }
    await store.send(.addToCart(product)) {
        $0.items = [product]
    }
}

Step 4: Define Device & OS Matrix

FactorStrategy
OS versionsTest on minimum supported + latest + one in between
Screen sizesSmall phone, standard phone, large phone / tablet
Device tiersAt least one low-end device for performance testing
OrientationsPortrait + landscape (if supported)
Network conditionsWiFi, 3G (throttled), offline
AccessibilityFont scaling (large text), TalkBack / VoiceOver enabled

Device farm options: Firebase Test Lab, AWS Device Farm, BrowserStack, Sauce Labs, Maestro Cloud

Step 5: Integrate with CI

StageTests to RunSpeed Target
Pre-commitLint + unit tests< 2 min
PR / merge requestUnit + widget/component + golden tests< 10 min
Post-mergeFull suite including integration tests on device farm< 30 min
NightlyE2E flows, performance benchmarks, full device matrix< 60 min

Step 6: Measure Coverage

MetricTargetTool
Line coverage (unit)> 80% for business logiclcov (Flutter), JaCoCo (Android), llvm-cov (iOS)
Critical flow coverage (E2E)100% of P0 user journeysManual tracking
Visual regressionNo unreviewed UI changesGolden tests / snapshot tests
AccessibilityPass automated a11y checksAccessibility Scanner (Android), Accessibility Inspector (iOS)

Output Format

## Test Strategy Summary
- **Platform:** [Flutter / Android / iOS]
- **Current Coverage:** [if known]
- **Target Coverage:** [goal]

## Test Pyramid
| Layer | Count | Coverage | Tools |
|-------|-------|----------|-------|
| Unit | ... | ... | ... |
| Widget/Component | ... | ... | ... |
| Integration/E2E | ... | ... | ... |

## Critical Test Cases
[P0 test cases with expected behavior]

## Device Matrix
[Devices, OS versions, conditions to test]

## CI Integration
[Which tests run at which stage]

Quality Checklist

  • Test pyramid is balanced (not top-heavy with E2E tests)
  • Business logic is unit-testable in isolation (no framework dependencies)
  • State management is tested independently from UI
  • Golden / snapshot tests cover key screens
  • CI runs tests on every PR
  • Device farm is configured for post-merge or nightly integration tests
  • Flaky tests are quarantined and tracked
  • Accessibility testing is included

Edge Cases

  • For Flutter add-to-app (embedded in native), test the platform channel boundary with mock channels on both sides
  • For apps using code generation (Freezed, json_serializable, Hilt), ensure generated code is up-to-date in CI before running tests
  • For white-label / multi-flavor apps, test each flavor's unique configuration
  • Flaky E2E tests are a common problem — quarantine them into a separate non-blocking CI job rather than skipping them entirely
  • For Kotlin Multiplatform shared code, test the shared module separately from platform-specific UI
我的收藏