Cross-Platform E2E Mock Testing Guide
This guide describes how to use the built-in Dummy BLE Adapter (Mock Mode) to run automated UI validation and End-to-End (E2E) tests. By enabling USE_MOCK_BLE, the clients will bypass the actual OS Bluetooth stack and instead inject a simulated device, allowing test runners to verify filtering, connection UI, and state management without physical hardware.
1. Overview of Mock Devices
When Mock Mode is enabled, the scanner will immediately identify the following simulated device upon pushing the Scan button:
- Id:
MOCK-11:22:33:44:55:66 - Name:
Dummy-BLE-01 - RSSI:
-45 - Connectable:
true - Services Implemented:
180A(Device Information),180D(Heart Rate) /FFF0(Custom)
2. Enabling Mock Mode per Platform
2.1 Flutter (Android/iOS)
The Mock flag is provided via the Dart --dart-define compilation environment. Running locally:
flutter run --dart-define=USE_MOCK_BLE=trueCI/CD Integration Testing:
flutter test integration_test/app_test.dart --dart-define=USE_MOCK_BLE=true2.2 Tauri (macOS/Windows)
The web view checks the URL search parameters to activate the Mock E2E injection. Development Run: Normally Tauri runs via cargo tauri dev. To inject the UI flag locally, you can modify the initialization in src/main.js or set an environment flag that adds ?mock=true to the webview URL. For manual browser debugging of the <device-card>:
// In developer tools console
window.location.search = "?mock=true";2.3 Electron (macOS/Windows/Linux)
Similar to Tauri, Electron's frontend renderer public/app.js is isolated and listens to the query parameter. Quick Start: Launch the app, open DevTools (Cmd/Ctrl+Option+I), and type:
window.location.search = "?mock=true";3. Recommended E2E Test Flow
When running UI automation (e.g. Playwright / Appium / Patrol), script your actions as follows:
- Initialize Application: Verify that "BLE Toolkit+" renders and the default state shows Bluetooth as running/stubbed.
- Start Scan: Click
[🔍 开始扫描]. Verify theDummy-BLE-01card appears within 1 second. - UI Filters:
- Set the "名称前缀" filter to
Dummy. Verify the card stays. - Set the "名称前缀" filter to
ESP. Verify the list becomes empty. - Clear the filter.
- Set the "名称前缀" filter to
- Connect Device: Click
[连接]on theDummy-BLE-01card.- Assert that the UI pivots to the
<ConnectedDevicesPage>Tab or<DeviceDetailView>. - Assert that Connection State shows "Connected".
- Assert that the UI pivots to the
- Multi-Device Tabs:
- Assert the
[已连接设备](Connected Devices) tab displays a badge of1.
- Assert the
- Disconnect:
- Click
[断开]. Assert the Connected Devices tab displays "暂无已连接设备" (No connected devices empty state).
- Click
4. Current Parity Status
| Feature | Flutter | Tauri | Electron | UniApp | iOS Native |
|---|---|---|---|---|---|
| Mock Injector Available | ✅ Yes | ✅ Yes (Query Param) | ✅ Yes (Query Param) | 🚧 Planned | 🚧 Planned |
| Automated E2E Framework | Patrol | Playwright/Tauri | Playwright | Minium | XCTest |
(Note: UniApp test automation should use WeChat's Minium framework, while iOS Native uses XCTest UI testing.)