57 / 66 · 09 Mobile & Cross-Platform Testing · On-Device ML Model Testing← prev⊞ allnext →☰ Read as one page
10.5Testing Fallback Behavior
When the on-device model fails to load (corrupted file, unsupported device, insufficient memory), the app must degrade gracefully to a server-side API.
def test_model_fallback_when_unavailable(driver):
"""App should fall back to server-side API when model fails to load."""
# Simulate model file corruption
driver.execute_script("mobile: shell", {
"command": "rm",
"args": ["/data/data/com.app/files/ml_model.tflite"]
})
# Restart app
driver.terminate_app("com.app")
driver.activate_app("com.app")
# Feature should still work (via server fallback)
driver.find_element(AppiumBy.ACCESSIBILITY_ID, "classify-image").click()
result = driver.find_element(AppiumBy.ACCESSIBILITY_ID, "classification-result")
assert result.is_displayed()
# Verify fallback indicator is shown
fallback_badge = driver.find_element(AppiumBy.ACCESSIBILITY_ID, "server-mode-indicator")
assert fallback_badge.is_displayed()
def test_fallback_to_server_on_low_memory(driver):
"""On low-memory devices, the app should use server-side inference."""
# Get available memory
memory_info = driver.execute_script("mobile: shell", {
"command": "cat",
"args": ["/proc/meminfo"]
})
# If available memory is under threshold, model may not load
# The app should detect this and use server-side inference
driver.find_element(AppiumBy.ACCESSIBILITY_ID, "classify-image").click()
result = driver.find_element(AppiumBy.ACCESSIBILITY_ID, "classification-result")
assert result.is_displayed() # Feature works regardless of inference path