Modern QA2026Memory and Battery Impact Testing — tiles
Log inJoin
59 / 66 · 09 Mobile & Cross-Platform Testing · On-Device ML Model Testing← prev⊞ allnext →☰ Read as one page

10.7Memory and Battery Impact Testing

def test_memory_usage_during_inference(driver):
    """Continuous inference must not cause memory growth."""
    # Get initial memory usage
    initial_memory = get_app_memory(driver)

    # Run 50 consecutive inferences
    for i in range(50):
        driver.find_element(AppiumBy.ACCESSIBILITY_ID, "classify-image").click()
        driver.find_element(AppiumBy.ACCESSIBILITY_ID, "classification-result")
        driver.find_element(AppiumBy.ACCESSIBILITY_ID, "clear-result").click()

    # Get final memory usage
    final_memory = get_app_memory(driver)

    # Memory should not grow significantly (allow 20% for caching)
    memory_growth = (final_memory - initial_memory) / initial_memory
    assert memory_growth < 0.20, \
        f"Memory grew by {memory_growth:.1%} during sustained inference"

def get_app_memory(driver):
    """Get the current memory usage of the app in MB."""
    result = driver.execute_script("mobile: shell", {
        "command": "dumpsys",
        "args": ["meminfo", "com.app", "--short"]
    })
    # Parse total PSS from output
    import re
    match = re.search(r'TOTAL\s+(\d+)', result)
    return int(match.group(1)) / 1024 if match else 0

On-device ML testing requires a blend of traditional functional testing (does it produce the right output?) and performance testing (does it do it fast enough, within memory constraints, without draining the battery?). The fallback behavior is the most critical test -- if the model fails, the user must still be able to use the feature.