How to Write Test Cases for Offline Mode (With Examples)
How to Write Test Cases for Offline Mode (With Examples): Core Principles
How to Write Test Cases for Offline Mode (With Examples): Core Principles
Writing test cases for offline mode requires a shift from typical online‑centric scenarios to situations where network connectivity is absent, intermittent, or degraded. The goal is to verify that the application continues to deliver core functionality, preserves data integrity, gracefully handles UI elements that depend on remote services, and recovers smoothly when connectivity returns. A well‑designed offline‑mode test suite catches crashes, ANRs, dead buttons, data loss, and misleading user feedback before they reach production.
The first step is to treat offline mode as a distinct feature area rather than an after‑thought. Identify every user flow that may be executed without a network—login, content browsing, form submission, media playback, settings changes, and any background sync. For each flow, enumerate the assumptions the code makes about network availability and replace those assumptions with explicit checks or fallbacks. This mindset drives the creation of test cases that are both high‑signal (they expose real defects) and maintainable (they map cleanly to requirements).
How to Write Test Cases for Offline Mode (With Examples): Anatomy of a High‑Signal Test Case
A test case that reliably uncovers offline‑mode issues follows a consistent structure. Each element serves a purpose: it makes the case reproducible, isolates variables, and clarifies the pass/fail criterion.
Test‑Case ID
A unique identifier (e.g., OFF‑001) enables traceability to requirements, test‑management tools, and change‑impact analysis. Use a prefix that signals the feature area (OFF for offline mode) and a sequential number.
Preconditions
Preconditions capture the exact state the device or browser must be in before execution. For offline mode this typically includes:
- Network interface disabled (airplane mode on, Wi‑Fi and cellular off, or Ethernet unplugged)
- Application installed to a known version
- Any required account logged in (if the test assumes an authenticated session)
- Data seed loaded (e.g., a local database populated with a specific set of records)
- Device locale, OS version, and any feature flags set
Steps
Steps are the atomic actions a tester or automation script performs. They should be imperative, concise, and free of ambiguity. Include any necessary waits or verification points. For example:
- Launch the app from the home screen.
- Navigate to the “My Orders” screen.
- Tap the “Refresh” button.
- Observe the UI for a loading indicator.
- Verify that a toast message reads “No internet connection”.
Expected Result
The expected result describes the observable outcome after the final step. It must be testable and unambiguous. For offline scenarios, expected results often involve:
- UI elements showing appropriate offline state (e.g., disabled buttons, placeholder text)
- No network calls made (verified via network sniffing or instrumentation)
- Local data persisted correctly
- Error messages that are user‑friendly and actionable
- Graceful degradation (e.g., read‑only mode) rather than a crash
Postconditions (optional)
Postconditions reset the device to a clean state for the next test, such as re‑enabling Wi‑Fi, clearing app data, or rebooting the emulator. Including them prevents state leakage that could mask defects.
Attachments / Logs
Link to relevant logs, screenshots, or video captures. Automated frameworks can attach logs automatically; manual testers should note where to find them.
How to Write Test Cases for Offline Mode (With Examples): Positive, Negative, Edge, and Boundary Cases for Offline Mode
Categorizing test ideas helps ensure coverage across the spectrum of possible behaviors.
#### Positive Cases
Positive cases verify that the application works as intended when offline, assuming the offline mode feature is correctly implemented. Examples:
- The app launches and displays cached content without attempting a network request.
- A user can submit a form; data is stored locally and queued for later sync.
- Media playback continues from a locally stored file.
#### Negative Cases
Negative cases check that the app does not perform prohibited actions when offline. Examples:
- Tapping a “Buy Now” button does not initiate a payment gateway call; instead, an inline error appears.
- Attempting to sign up with a new account fails with a clear message that network is required.
- Pull‑to‑refresh does not trigger a spinner indefinitely; it stops after a timeout and shows an offline banner.
#### Edge Cases
Edge cases explore unusual but plausible conditions that sit at the limits of normal operation. Examples:
- The device switches from online to offline mid‑transaction; the app rolls back the operation and notifies the user.
- The app receives a push notification while offline; it stores the notification and displays it once connectivity is restored.
- The user enables airplane mode, then immediately disables it; the app resumes sync without duplicating queued actions.
#### Boundary Cases
Boundary cases focus on limits of data, timing, or resource usage. Examples:
- The local storage quota is exceeded while queuing offline actions; the app shows a storage‑full warning and stops accepting new inputs.
- A large file (e.g., 100 MB) is attempted to be downloaded while offline; the app fails gracefully and does not corrupt existing files.
- The app’s offline timer (time after which queued actions are discarded) is set to 0 seconds; actions are discarded immediately upon going offline.
How to Write Test Cases for Offline Mode (With Examples): Building the Test Matrix
A test matrix translates the categorized ideas into concrete, executable items. Below is a worked example for a typical offline‑first mobile banking app that supports account balance viewing, fund transfers, bill payments, and profile updates. The table lists 22 test cases; each row includes ID, preconditions, steps, and expected result.
| ID | Preconditions | Steps | Expected Result |
|---|---|---|---|
| OFF‑001 | App v2.3.1 installed; user logged in; airplane mode ON; Wi‑Fi & cellular OFF | 1. Open app → 2. Navigate to “Accounts” tab → 3. View balance | Balance shown matches last synced value; no network request logged; UI shows “Offline” badge |
| OFF‑002 | Same as OFF‑001 | 1. Open app → 2. Tap “Transfer” → 3. Enter amount and recipient → 4. Tap “Submit” | Transfer form accepts input; submission shows “Saved for later sync” toast; transaction appears in “Pending” list; no network call made |
| OFF‑003 | Same as OFF‑001 | 1. Open app → 2. Navigate to “Bills” → 3. Tap “Add New Bill” → 4. Fill details → 5. Tap “Save” | Bill saved locally; appears in “My Bills” list with a sync icon; no network traffic |
| OFF‑004 | Same as OFF‑001 | 1. Open app → 2. Go to “Profile” → 3. Change “Display Name” → 4. Tap “Save” | Name change stored locally; profile screen reflects new name instantly; offline indicator present |
| OFF‑005 | Same as OFF‑001 | 1. Open app → 2. Attempt to log out | Logout button disabled; tooltip reads “Requires internet to sign out”; user remains logged in |
| OFF‑006 | Same as OFF‑001 | 1. Open app → 2. Navigate to “Settings” → 3. Toggle “Biometric Login” ON | Setting change saved locally; toggle reflects new state; no network request |
| OFF‑007 | Same as OFF‑001 | 1. Open app → 2. Start video tutorial → 3. Play 10 seconds | Video plays from cached asset; playback continues without buffering spinner |
| OFF‑008 | Same as OFF‑001 | 1. Open app → 2. Pull‑to‑refresh on “Accounts” screen | Refresh animation stops after 800 ms; banner shows “No internet connection”; account list unchanged |
| OFF‑009 | Same as OFF‑001 | 1. Open app → 2. Receive push notification (sent via FCM while offline) | Notification stored; appears in notification tray; tapping opens app and shows relevant screen |
| OFF‑010 | Same as OFF‑001 | 1. Open app → 2. Navigate to “Transfer” → 3. Enter amount exceeding daily limit → 4. Tap “Submit” | Input rejected with inline error “Amount exceeds limit”; no network call; transaction not added to pending list |
| OFF‑011 | Same as OFF‑001 | 1. Open app → 2. Begin transfer → 3. Switch airplane mode OFF (online) after 2 seconds → 4. Wait for sync | Transfer automatically retries; success toast appears; transaction moves from pending to completed; network call observed |
| OFF‑012 | Same as OFF‑001 | 1. Open app → 2. Begin transfer → 3. Switch airplane mode OFF after 2 seconds → 4. Immediately toggle airplane mode ON again | Transfer remains in pending state; no duplicate submission; retry occurs once connectivity stable |
| OFF‑013 | Same as OFF‑001 | 1. Open app → 2. Fill profile form with 200‑character bio → 3. Tap “Save” | Bio saved locally; character counter shows remaining; UI accepts input; no network traffic |
| OFF‑014 | Same as OFF‑001 | 1. Open app → 2. Attempt to upload profile picture (5 MB) while offline | Upload button shows error “Network required”; image not added to queue |
| OFF‑015 | Same as OFF‑001 | 1. Open app → 2. Navigate to “Statements” → 3. Request last 3 months (requires server) | Message appears: “Statement retrieval needs internet”; cached statements from last sync remain visible |
| OFF‑016 | Same as OFF‑001 | 1. Open app → 2. Enable “Data Saver” mode → 3. Attempt to view transaction details | Details load from local cache; images shown as placeholders; no high‑resolution fetch |
| OFF‑017 | Same as OFF‑001 | 1. Open app → 2. Rapidly tap “Refresh” button 10 times | UI shows only one offline banner; no flood of toast messages; app remains responsive |
| OFF‑018 | Same as OFF‑001 | 1. Open app → 2. Leave app in background for 30 minutes with airplane mode ON | App state preserved; returning to foreground shows same offline screen; no crash or ANR |
| OFF‑019 | Same as OFF‑001 | 1. Open app → 2. Navigate to “Help Center” → 3. Search for term (requires online) | Search field shows hint “Search unavailable offline”; results list shows cached FAQs only |
| OFF‑020 | Same as OFF‑001 | 1. Open app → 2. Go to “Settings” → 3. Tap “Clear Cache” | Local cache cleared; offline indicators persist; app does not crash; reopening shows empty state where data previously cached |
| OFF‑021 | Same as OFF‑001 | 1. Open app → 2. Attempt to add a new payee (requires server validation) | Add payee button disabled; tooltip “Need internet to validate payee”; existing payees list unchanged |
| OFF‑022 | Same as OFF‑001 | 1. Open app → 2. Simulate low storage (via adb shell cmd battery set status 2 and fill storage) → 3. Try to save a new bill | Save fails with toast “Insufficient storage”; no bill added; app remains usable |
*Notes*: Steps that involve toggling airplane mode can be performed via the UI or using adb shell svc wifi disable && adb shell svc data disable. For web tests, Chrome DevTools → Network → Offline achieves the same state.
How to Write Test Cases for Offline Mode (With Examples): Data Setup and Environment Preparation
Reliable offline testing hinges on reproducible data and controllable network conditions.
#### Android
- Airplane mode:
adb shell settings put global airplane_mode_on 1 && adb shell am broadcast -a android.intent.action.AIRPLANE_MODE --ez state true - Selective disabling:
adb shell svc wifi disable && adb shell svc data disable(re‑enable withenable). - Network throttling to zero:
adb shell tc qdisc add dev wlan0 root netem loss 100%(replacewlan0with the active interface). - Data seeding: Use Android Debug Bridge to push a JSON file into the app’s private directory, then launch the app with a flag that loads the seed (
adb shell am start -n com.example.app/.MainActivity --ez load_seed true). - Clearing state:
adb shell pm clear com.example.appremoves databases and shared preferences; follow with a fresh install if needed.
#### iOS
- Airplane mode: Enable via Settings → Airplane Mode, or use
xcrun simctl status_bar booted override --airPlaneMode true. - Wi‑Fi/Cellular toggle:
xcrun simctl io booted wifi offandxcrun simctl io booted cellular off. - Network link conditioner: Install the Additional Tools for Xcode package, then create a profile with 100 % loss and apply via
xcrun simctl io booted networkinterface en0 set-configuration. - Data seeding: Utilize UIAutomation scripts to inject a JSON file into the app’s Documents folder, or use a launch argument (
-SeedData) if the app supports it. - Clean slate:
xcrun simctl erase bootedwipes the simulator entirely.
#### Web (Chrome/Firefox)
- Offline toggle: Open DevTools → Network → check “Offline”.
- Custom throttling: DevTools → Network → throttling preset → “Slow 3G”, or set custom values (0 kbps download/upload, 500 ms latency).
- Service worker testing: Unregister or update the service worker via
navigator.serviceWorker.getRegistrations().then(r => r[0].unregister()). - Cache seeding: Use
localStorageor IndexedDB to prepopulate data before disabling network. - Automation: With Playwright, launch context with
context.setOffline(true);or usepage.route('**/*.{js,css,png}', route => route.abort())to block specific resources.
#### General Tips
- Always verify the network state before each step (e.g.,
adb shell dumpsys connectivityornavigator.onLinein JS). - Record logs with
adb logcat(Android) orxcrun simctl spawn booted log stream(iOS) to confirm no unexpected network attempts. - For CI pipelines, Docker containers can simulate offline mode using
tcrules on the host network namespace.
How to Write Test Cases for Offline Mode (With Examples): Manual Execution vs Automated Scripts
Both manual and automated approaches have merit. The table below contrasts them across key dimensions relevant to offline‑mode testing.
| Dimension | Manual Testing | Automated Testing |
|---|---|---|
| Setup speed | Quick for ad‑hoc checks; requires device handling each time | Initial script development takes time; subsequent runs are fast |
| Repeatability | Human error can cause missed steps; depends on tester diligence | Highly repeatable; same steps executed identically each run |
| Exploratory flexibility | Tester can deviate, notice odd UI glitches, try unconventional paths | Limited to scripted paths unless combined with exploratory frameworks |
| Cost | Low upfront, higher ongoing labor | Higher upfront (framework, device lab), lower marginal cost per execution |
| Coverage of edge cases | Good for discovering unexpected interactions | Excellent for regression; can stress boundaries with loops and data generators |
| Tooling required | Device, possibly USB cable | Test framework (Appium, Espresso, XCTest, Playwright), device cloud or local emulators, CI integration |
| Feedback cycle | Immediate visual feedback; tester can annotate screenshots | Depends on test runner; logs and screenshots need to be parsed |
| Suitability for offline | Ideal for verifying UI text, toast messages, and sensory feedback | Ideal for verifying absence of network calls, data persistence, and sync logic |
A balanced strategy uses manual testing for early‑stage validation of new offline flows and exploratory checks, while automation guards against regressions and validates large data sets.
How to Write Test Cases for Offline Mode (With Examples): Prioritization and Traceability
Not all test cases carry equal risk. Prioritization ensures limited testing time focuses on the scenarios most likely to cause user‑visible harm or revenue loss.
#### Risk‑Based Priority Levels
- P0 (Critical): Scenarios where data loss, financial incorrectness, or security exposure could occur. Example: submitting a fund transfer while offline that later duplicates or fails to persist.
- P1 (High): Core user journeys that must remain usable offline, such as viewing cached account balances or reading articles.
- P2 (Medium): Enhancements or secondary features where offline degradation is tolerable but should be graceful (e.g., unable to upload a profile picture).
- P3 (Low): Nice‑to‑have interactions that rarely affect core value, like browsing animated tutorials that require online assets.
Assign each test case a priority label in the test‑management tool. During a sprint, execute all P0 and P1 cases; schedule P2 for nightly runs; reserve P3 for weekly exploratory sessions.
#### Traceability Matrix
Link each test case to one or more requirements (user stories, design specs, or regulatory clauses). A simple matrix helps answer “If this requirement changes, which tests are affected?” and “Does every requirement have at least one verifying test?”
| Requirement ID | Description | Covered By Test IDs |
|---|---|---|
| REQ‑OFF‑01 | Display cached data when no network | OFF‑001, OFF‑008, OFF‑016 |
| REQ‑OFF‑02 | Queue user‑initiated actions for later sync | OFF‑002, OFF‑003, OFF‑004, OFF‑005 |
| REQ‑OFF‑03 | Prevent prohibited online‑only actions offline | OFF‑006, OFF‑007, OFF‑011, OFF‑012 |
| REQ‑OFF‑04 | Notify user of connectivity loss clearly | OFF‑008, OFF‑009, OFF‑015, OFF‑019 |
| REQ‑OFF‑05 | Handle storage limits gracefully | OFF‑021, OFF‑022 |
| REQ‑OFF‑06 | Preserve app state across background/offline | OFF‑010, OFF‑013, OFF‑014, OFF‑018 |
| REQ‑OFF‑07 | Recover and sync queued actions on reconnect | OFF‑002 (retry), OFF‑003 (retry) |
Maintain this matrix in a spreadsheet or a dedicated traceability plugin; update it whenever a requirement is added, modified, or removed.
How to Write Test Cases for Offline Mode (With Examples): Leveraging Autonomous Exploration (SUSA) to Augment Manual Cases
Modern QA workflows benefit from combining scripted test cases with intelligent, self‑directed exploration. SUSA (SUSATest) is an autonomous QA platform that, given an APK or a web URL, drives the application through realistic user interactions without pre‑written scripts. It models several personas—curious, impatient, novice, accessibility‑aware, power user, and even adversarial—to uncover issues that scripted cases might miss.
When applied to offline‑mode testing, SUSA can:
- Discover hidden navigation paths that lead to screens requiring network calls but are not covered in the manual matrix (e.g., a deep‑linked promotional banner that attempts to fetch a video).
- Vary timing of connectivity loss by toggling airplane mode at random points during a session, revealing race conditions between UI state changes and background sync tasks.
- Test multiple personas simultaneously; for example, the “impatient” persona may rapidly tap buttons while offline, exposing toast‑spamming or UI lock‑up issues that a methodical manual tester might not trigger.
- Generate regression artifacts; after each run, SUSA exports Appium scripts for Android and Playwright scripts for the web, capturing the exact sequences it exercised. These scripts can be added to the automated suite, continuously expanding coverage.
- Track learning across sessions; the platform remembers which screens have been visited and which actions led to dead ends, so subsequent runs focus on unexplored areas, increasing efficiency over time.
To invoke SUSA for an offline‑mode test, first ensure the device or emulator is in the desired network state (airplane mode on). Then run the CLI:
pip install susatest-agent # if not already installed
susatest run \
--app ./my‑app.apk \
--offline \
--personas curious impatient power \
--output-dir ./susa‑run‑2025‑09‑26 \
--generate‑scripts
The --offline flag tells SUSA to disable network before launching the app and to keep it disabled throughout the session. The resulting scripts appear under ./susa‑run‑2025‑09‑26/scripts and can be committed to the repository alongside hand‑written Appium or Playwright tests.
How to Write Test Cases for Offline Mode (With Examples): Checklist for Reviewing Offline‑Mode Test Suites
Before signing off a test suite, run through this concise checklist to confirm that it addresses the most common sources of offline‑mode defects.
- [ ] Network state verification: Each test case begins with a confirmed offline condition (airplane mode on, Wi‑Fi/cellular disabled, or DevTools offline).
- [ ] No false network calls: Use a network sniffer (e.g.,
adb logcat | grep "HTTP"or Chrome DevTools) to ensure the app does not attempt a request that should be blocked. - [ ] User‑visible feedback: Offline states are communicated via toast, banner, placeholder, or disabled controls—not silent failure.
- [ ] Data persistence: Any user input generated offline is stored locally and survives app kill/reboot.
- [ ] Sync correctness: When connectivity is restored, queued actions are applied exactly once, in the correct order, and conflicts are resolved according to business rules.
- [ ] Graceful degradation: Features that require online resources are hidden or disabled, with a clear indication why they are unavailable.
- [ ] Storage limits: Tests cover scenarios where local storage is exhausted, verifying that the app notifies the user and stops accepting new data.
- [ ] Background behavior: The app maintains correct state when moved to background while offline and resumes without corruption upon foreground.
- [ ] Accessibility: Offline error messages and UI states meet WCAG contrast and screen‑reader readability requirements.
- [ ] Recovery from interruptions: Simulate loss of connectivity mid‑transaction (e.g., toggle airplane mode after a few seconds) and verify rollback or resumption logic.
- [ ] Performance: UI remains responsive; no ANRs or excessive battery drain observed during prolonged offline usage.
- [ ] Cross‑platform consistency: For hybrid apps, verify that the offline behavior matches on Android, iOS, and web wrappers.
If any item is unchecked, revisit the corresponding test cases or add new ones to fill the gap.
How to Write Test Cases for Offline Mode (With Examples): Closing Takeaways
Writing effective test cases for offline mode is a disciplined exercise in defining precise preconditions, scripted steps, and observable expectations. By decomposing the feature into positive, negative, edge, and boundary scenarios, and by recording them in a structured matrix, teams gain repeatable coverage that catches data‑loss, sync faults, and misleading UI before they reach users. Pairing these manually crafted cases with autonomous exploration—using tools like SUSA—extends reach into unexpected pathways and generates reusable regression scripts. Prioritization based on risk, coupled with a traceability matrix, ensures that testing effort aligns with business impact and regulatory demands. Finally, a concise review checklist guards against common oversights such as hidden network calls or inadequate offline feedback. Apply these principles consistently, and your offline‑mode test suite will become a reliable safety net for any application that must stay useful when the network disappears.
Test Your App Autonomously
Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.
Try SUSA Free