Add tests
This commit is contained in:
100
tests/README.md
Normal file
100
tests/README.md
Normal file
@@ -0,0 +1,100 @@
|
||||
# KumaCLI Tests
|
||||
|
||||
This directory contains the test suite for kumacli.
|
||||
|
||||
## Running Tests
|
||||
|
||||
### Prerequisites
|
||||
|
||||
Install test dependencies:
|
||||
```bash
|
||||
pip install -e ".[test]"
|
||||
# or
|
||||
pip install pytest pytest-cov
|
||||
```
|
||||
|
||||
### Run All Tests
|
||||
|
||||
```bash
|
||||
# Using pytest directly
|
||||
python3 -m pytest
|
||||
|
||||
# Using the test runner script
|
||||
python3 run_tests.py
|
||||
|
||||
# From the project root
|
||||
python3 -m pytest tests/
|
||||
```
|
||||
|
||||
### Run Specific Tests
|
||||
|
||||
```bash
|
||||
# Test a specific file
|
||||
pytest tests/test_info.py
|
||||
|
||||
# Test a specific class
|
||||
pytest tests/test_monitor.py::TestMonitorCommands
|
||||
|
||||
# Test a specific method
|
||||
pytest tests/test_monitor.py::TestMonitorCommands::test_pause_monitors_by_pattern
|
||||
```
|
||||
|
||||
### Run Tests with Coverage
|
||||
|
||||
```bash
|
||||
pytest --cov=kumacli --cov-report=html
|
||||
python run_tests.py --cov
|
||||
```
|
||||
|
||||
### Test Options
|
||||
|
||||
```bash
|
||||
# Verbose output
|
||||
pytest -v
|
||||
|
||||
# Stop on first failure
|
||||
pytest -x
|
||||
|
||||
# Run tests in parallel (requires pytest-xdist)
|
||||
pytest -n auto
|
||||
```
|
||||
|
||||
## Test Structure
|
||||
|
||||
- `conftest.py` - Shared fixtures and test configuration
|
||||
- `test_info.py` - Tests for the info command
|
||||
- `test_monitor.py` - Tests for monitor commands (list, pause, resume)
|
||||
- `test_maintenance.py` - Tests for maintenance commands
|
||||
- `test_client.py` - Tests for the KumaClient class
|
||||
- `test_cli_integration.py` - Integration tests for CLI functionality
|
||||
|
||||
## Test Coverage
|
||||
|
||||
The tests cover:
|
||||
|
||||
- ✅ Command argument parsing
|
||||
- ✅ API method calls and responses
|
||||
- ✅ Error handling and edge cases
|
||||
- ✅ Help message functionality
|
||||
- ✅ Monitor pause/resume operations
|
||||
- ✅ Maintenance operations
|
||||
- ✅ Client utility functions
|
||||
- ✅ Integration between components
|
||||
|
||||
## Mock Strategy
|
||||
|
||||
Tests use unittest.mock to:
|
||||
- Mock the UptimeKumaApi calls
|
||||
- Simulate API responses and errors
|
||||
- Test command logic without requiring a live server
|
||||
- Verify correct API method calls with expected parameters
|
||||
|
||||
## Adding New Tests
|
||||
|
||||
When adding new functionality:
|
||||
|
||||
1. Add unit tests for the new commands/methods
|
||||
2. Add integration tests if the feature involves multiple components
|
||||
3. Test both success and error cases
|
||||
4. Mock external dependencies (API calls, file operations)
|
||||
5. Use descriptive test names that explain what is being tested
|
Reference in New Issue
Block a user