<!--
title: Test independence design
domain: ml-systems
topic: Testing
language: Python
source: commaai/openpilot
updated: 2025-08-22
url: https://awesomereviewers.com/reviewers/openpilot-test-independence-design/
-->

Tests should be designed to be independent and avoid coupling to implementation details. Use public interfaces rather than accessing internal state, prefer mocked or fake data over external dependencies, and keep tests general rather than tightly coupled to specific implementations.

Key principles:
- Avoid accessing internal state like `raw_points` in test cases - use proper public interfaces like `handle_log` instead
- Use made-up or mocked data rather than requiring external handlers when the test doesn't specifically need to test that integration
- Design tests to know as little as possible about specific implementations (e.g., car brands) to keep them general and maintainable

Example of good practice:
```python
# Instead of accessing internal state:
est.raw_points["lat_active"].append(True)

# Use the public interface:
est.handle_log(log_message)
```

This approach makes tests more maintainable, less brittle to refactoring, and easier to understand by focusing on the component's public contract rather than its internal implementation.
