Skip to content

Latest commit

 

History

History
344 lines (281 loc) · 7.86 KB

File metadata and controls

344 lines (281 loc) · 7.86 KB

Android Testing Engineer's Comprehensive Guide

Table of Contents

  1. Types of Testing
  2. Android-Specific Testing
  3. Automation Frameworks & Tools
  4. Performance Testing
  5. Battery & Power Testing
  6. Graphics & UI Testing
  7. Modem & Connectivity Testing
  8. Advanced Testing Concepts
  9. Best Practices & Tips

Types of Testing

Functional Testing

  • Unit Testing

    • JUnit for Java components
    • Robolectric for Android-specific unit tests
    • MockK for Kotlin mocking
    • Tips: Use @SmallTest annotation, keep tests isolated
  • Integration Testing

    • Testing component interactions
    • Database integration tests
    • Content provider testing
    • Service integration testing
  • System Testing

    • End-to-end scenarios
    • Cross-app interactions
    • System permissions testing
    • Hardware integration testing
  • Acceptance Testing

    • User acceptance testing (UAT)
    • Beta testing
    • Field testing
    • Dogfooding

Non-Functional Testing

  • Performance Testing

    • Startup time
    • Frame rate (FPS)
    • Memory usage
    • CPU utilization
    • Network performance
    • Storage I/O
  • Security Testing

    • Penetration testing
    • Vulnerability scanning
    • Permission model testing
    • Data encryption verification
    • Secure communication testing

Android-Specific Testing

Activity Testing

@Test
def test_activity_lifecycle():
    # Launch activity
    scenario = ActivityScenario.launch(MainActivity::class.java)
    
    # Test different states
    scenario.moveToState(State.CREATED)
    scenario.moveToState(State.STARTED)
    scenario.moveToState(State.RESUMED)
    
    # Verify state
    scenario.onActivity { activity ->
        assertTrue(activity.isResumed())
    }

Fragment Testing

  • Fragment scenarios
  • Navigation testing
  • Configuration change handling
  • State preservation testing

Intent Testing

  • Implicit intents
  • Explicit intents
  • Intent filters
  • Deep linking validation

Automation Frameworks & Tools

UI Automation

  1. Espresso

    • View matchers
    • View actions
    • View assertions
    • IdlingResources for async operations
  2. UI Automator

    • System UI testing
    • Cross-app testing
    • Device-level interactions
  3. Appium

    • Cross-platform testing
    • Real device testing
    • Cloud device farm integration

Performance Automation

def measure_startup_time():
    """
    Measures cold and warm start times
    """
    adb shell am force-stop com.example.app
    start_time = time.time()
    
    # Launch app
    subprocess.run(['adb', 'shell', 'am', 'start-activity', 
                   'com.example.app/.MainActivity'])
    
    # Wait for launch complete
    while not check_activity_resumed():
        if time.time() - start_time > TIMEOUT:
            raise TimeoutError("App launch timeout")
    
    return time.time() - start_time

Performance Testing

Key Metrics

  1. Startup Performance

    • Cold start time
    • Warm start time
    • Hot start time
    • Time to first frame
  2. Runtime Performance

    • Frame time
    • Jank detection
    • Memory leaks
    • Battery consumption
    • Network efficiency

Tools & Commands

# Capture traces
adb shell perfetto -c /data/misc/perfetto-configs/config.pb -o /data/misc/perfetto-traces/trace.perfetto-trace

# Analyze memory
adb shell dumpsys meminfo package_name

# Check battery stats
adb shell dumpsys batterystats

# Monitor frame metrics
adb shell dumpsys gfxinfo package_name

Battery & Power Testing

Test Scenarios

  1. Screen-on Tests

    • Different brightness levels
    • Various refresh rates
    • Content types (static vs dynamic)
  2. Background Operations

    • Background service impact
    • Wake lock usage
    • Network activity
    • Location updates
  3. Doze Mode Testing

    • App standby buckets
    • Background restrictions
    • Whitelist behavior

Battery Testing Script

class BatteryTest:
    def setup(self):
        # Disable auto-brightness
        subprocess.run(['adb', 'shell', 'settings', 'put', 'system', 
                       'screen_brightness_mode', '0'])
        
        # Set specific brightness
        subprocess.run(['adb', 'shell', 'settings', 'put', 'system',
                       'screen_brightness', '128'])
        
    def measure_battery_drain(self, duration_minutes):
        # Get initial battery level
        initial = self.get_battery_level()
        
        # Run test scenario
        time.sleep(duration_minutes * 60)
        
        # Get final battery level
        final = self.get_battery_level()
        
        return {
            'drain_percentage': initial - final,
            'drain_rate': (initial - final) / duration_minutes
        }

Graphics & UI Testing

Performance Metrics

  • Frame timing
  • GPU utilization
  • Texture memory usage
  • Overdraw analysis
  • Layout performance

Testing Tools

  1. GPU Rendering Analysis

    • Profile GPU rendering
    • Debug GPU overdraw
    • Systrace analysis
  2. Layout Inspector

    • View hierarchy analysis
    • Layout performance
    • Memory impact

Modem & Connectivity Testing

Network Scenarios

  1. Network Types

    • 2G/3G/4G/5G transitions
    • WiFi handling
    • Bluetooth operations
    • NFC testing
  2. Network Conditions

    • Poor connectivity
    • High latency
    • Packet loss
    • Network transitions

Network Testing Script

def test_network_transitions():
    """
    Tests app behavior during network changes
    """
    # Enable airplane mode
    subprocess.run(['adb', 'shell', 'settings', 'put', 'global',
                   'airplane_mode_on', '1'])
    
    # Broadcast change
    subprocess.run(['adb', 'shell', 'am', 'broadcast', '-a',
                   'android.intent.action.AIRPLANE_MODE'])
    
    # Verify app behavior
    check_app_state()
    
    # Disable airplane mode
    subprocess.run(['adb', 'shell', 'settings', 'put', 'global',
                   'airplane_mode_on', '0'])

Advanced Testing Concepts

Monkey Testing

def run_monkey_test():
    """
    Runs monkey test with specific parameters
    """
    cmd = [
        'adb', 'shell', 'monkey',
        '-p', 'com.example.app',
        '--throttle', '500',
        '-v', '-v',
        '--ignore-crashes',
        '--ignore-timeouts',
        '--monitor-native-crashes',
        '10000'
    ]
    subprocess.run(cmd)

Continuous Testing

  1. CI/CD Integration

    • Jenkins pipeline setup
    • GitHub Actions integration
    • Test automation triggers
    • Report generation
  2. Test Coverage

    • Code coverage metrics
    • Feature coverage tracking
    • Risk-based testing
    • Regression coverage

Best Practices & Tips

Testing Strategy

  1. Test Planning

    • Risk assessment
    • Test prioritization
    • Resource allocation
    • Timeline planning
  2. Test Design

    • Boundary value analysis
    • Equivalence partitioning
    • State transition testing
    • Error guessing

Tips & Tricks

  1. Performance Testing

    • Always test on low-end devices
    • Use strict mode in development
    • Monitor ANR situations
    • Track startup performance
  2. Battery Testing

    • Test with different battery levels
    • Monitor wake locks
    • Check background operations
    • Validate doze mode behavior
  3. Automation

    • Use page object pattern
    • Implement robust waits
    • Handle flaky tests
    • Maintain test data

Rarely Known Facts

  1. Testing Efficiency

    • Use testOnly build variant
    • Enable developer options
    • Use shell commands for quick testing
    • Leverage monkey testing effectively
  2. Debug Techniques

    • Use layout bounds
    • Enable strict mode
    • Track overdraw
    • Monitor memory allocations