| 1 |
# Fenrir Test Suite |
| 2 |
|
| 3 |
This directory contains automated tests for the Fenrir screen reader. Testing a screen reader that requires root access and hardware interaction presents unique challenges, so we use a multi-layered testing strategy. |
| 4 |
|
| 5 |
## Test Strategy |
| 6 |
|
| 7 |
### 1. Unit Tests (No Root Required) |
| 8 |
Test individual components in isolation without requiring hardware access: |
| 9 |
- **Core Managers**: Logic testing without driver dependencies |
| 10 |
- **Utility Functions**: String manipulation, cursor calculations, text processing |
| 11 |
- **Settings Validation**: Configuration parsing and validation |
| 12 |
- **Remote Command Parsing**: Command/setting string processing |
| 13 |
|
| 14 |
### 2. Integration Tests (No Root Required) |
| 15 |
Test component interactions using mocked drivers: |
| 16 |
- **Remote Control**: Unix socket and TCP communication |
| 17 |
- **Command System**: Command loading and execution flow |
| 18 |
- **Event Processing**: Event queue and dispatching |
| 19 |
- **Settings Manager**: Configuration loading and runtime changes |
| 20 |
|
| 21 |
### 3. Driver Tests (Root Required, Optional) |
| 22 |
Test actual hardware interaction (only run in CI or explicitly by developers): |
| 23 |
- **VCSA Driver**: Screen reading on real TTY |
| 24 |
- **Evdev Driver**: Keyboard input capture |
| 25 |
- **Speech Drivers**: TTS output validation |
| 26 |
- **Sound Drivers**: Audio playback testing |
| 27 |
|
| 28 |
### 4. End-to-End Tests (Root Required, Manual) |
| 29 |
Real-world usage scenarios run manually by developers: |
| 30 |
- Full Fenrir startup/shutdown cycle |
| 31 |
- Remote control from external scripts |
| 32 |
- VMenu navigation and command execution |
| 33 |
- Speech output for screen changes |
| 34 |
|
| 35 |
## Running Tests |
| 36 |
|
| 37 |
```bash |
| 38 |
# Install test dependencies |
| 39 |
pip install pytest pytest-cov pytest-mock pytest-timeout |
| 40 |
|
| 41 |
# Run all unit and integration tests (no root required) |
| 42 |
pytest tests/ |
| 43 |
|
| 44 |
# Run with coverage report |
| 45 |
pytest tests/ --cov=src/fenrirscreenreader --cov-report=html |
| 46 |
|
| 47 |
# Run only unit tests |
| 48 |
pytest tests/unit/ |
| 49 |
|
| 50 |
# Run only integration tests |
| 51 |
pytest tests/integration/ |
| 52 |
|
| 53 |
# Run specific test file |
| 54 |
pytest tests/unit/test_settings_manager.py |
| 55 |
|
| 56 |
# Run with verbose output |
| 57 |
pytest tests/ -v |
| 58 |
|
| 59 |
# Run driver tests (requires root) |
| 60 |
sudo pytest tests/drivers/ -v |
| 61 |
``` |
| 62 |
|
| 63 |
## Test Organization |
| 64 |
|
| 65 |
``` |
| 66 |
tests/ |
| 67 |
├── README.md # This file |
| 68 |
├── conftest.py # Shared pytest fixtures |
| 69 |
├── unit/ # Unit tests (fast, no mocking needed) |
| 70 |
│ ├── test_settings_validation.py |
| 71 |
│ ├── test_cursor_utils.py |
| 72 |
│ ├── test_text_utils.py |
| 73 |
│ └── test_remote_parsing.py |
| 74 |
├── integration/ # Integration tests (require mocking) |
| 75 |
│ ├── test_remote_control.py |
| 76 |
│ ├── test_command_manager.py |
| 77 |
│ ├── test_event_manager.py |
| 78 |
│ └── test_settings_manager.py |
| 79 |
└── drivers/ # Driver tests (require root) |
| 80 |
├── test_vcsa_driver.py |
| 81 |
├── test_evdev_driver.py |
| 82 |
└── test_speech_drivers.py |
| 83 |
``` |
| 84 |
|
| 85 |
## Writing Tests |
| 86 |
|
| 87 |
### Example Unit Test |
| 88 |
```python |
| 89 |
def test_speech_rate_validation(): |
| 90 |
"""Test that speech rate validation rejects out-of-range values.""" |
| 91 |
manager = SettingsManager() |
| 92 |
|
| 93 |
# Valid values should pass |
| 94 |
manager._validate_setting_value('speech', 'rate', 0.5) |
| 95 |
manager._validate_setting_value('speech', 'rate', 3.0) |
| 96 |
|
| 97 |
# Invalid values should raise ValueError |
| 98 |
with pytest.raises(ValueError): |
| 99 |
manager._validate_setting_value('speech', 'rate', -1.0) |
| 100 |
with pytest.raises(ValueError): |
| 101 |
manager._validate_setting_value('speech', 'rate', 10.0) |
| 102 |
``` |
| 103 |
|
| 104 |
### Example Integration Test |
| 105 |
```python |
| 106 |
def test_remote_control_unix_socket(tmp_path): |
| 107 |
"""Test Unix socket remote control accepts commands.""" |
| 108 |
socket_path = tmp_path / "test.sock" |
| 109 |
|
| 110 |
# Start mock remote driver |
| 111 |
driver = MockUnixDriver(socket_path) |
| 112 |
|
| 113 |
# Send command |
| 114 |
send_remote_command(socket_path, "command say Hello") |
| 115 |
|
| 116 |
# Verify command was received |
| 117 |
assert driver.received_commands[-1] == "command say Hello" |
| 118 |
``` |
| 119 |
|
| 120 |
## Test Coverage Goals |
| 121 |
|
| 122 |
- **Unit Tests**: 80%+ coverage on utility functions and validation logic |
| 123 |
- **Integration Tests**: 60%+ coverage on core managers and command system |
| 124 |
- **Overall**: 70%+ coverage on non-driver code |
| 125 |
|
| 126 |
Driver code is excluded from coverage metrics as it requires hardware interaction. |
| 127 |
|
| 128 |
## Continuous Integration |
| 129 |
|
| 130 |
Tests are designed to run in CI environments without root access: |
| 131 |
- Unit and integration tests run on every commit |
| 132 |
- Driver tests are skipped in CI (require actual hardware) |
| 133 |
- Coverage reports are generated and tracked over time |
| 134 |
|
| 135 |
## Test Principles |
| 136 |
|
| 137 |
1. **No Root by Default**: Most tests should run without elevated privileges |
| 138 |
2. **Fast Execution**: Unit tests complete in <1 second each |
| 139 |
3. **Isolated**: Tests don't depend on each other or external state |
| 140 |
4. **Deterministic**: Tests produce same results every run |
| 141 |
5. **Documented**: Each test has a clear docstring explaining what it tests |
| 142 |
6. **Realistic Mocks**: Mocked components behave like real ones |
| 143 |
|
| 144 |
## Future Enhancements |
| 145 |
|
| 146 |
- **Performance Tests**: Measure input-to-speech latency |
| 147 |
- **Stress Tests**: Rapid event processing, memory leak detection |
| 148 |
- **Accessibility Tests**: Verify all features work without vision |
| 149 |
- **Compatibility Tests**: Test across different Linux distributions |