init: common-skills v1
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
---
|
||||
name: testing-skill
|
||||
description: Testing best practices for Python and general projects. Use when writing unit tests, debugging test failures, or improving test coverage.
|
||||
---
|
||||
|
||||
# Testing Skill
|
||||
|
||||
## Test Structure (AAA Pattern)
|
||||
|
||||
```python
|
||||
def test_decision_layer_returns_action():
|
||||
# Arrange
|
||||
state = {"health": 80, "enemy_visible": True}
|
||||
|
||||
# Act
|
||||
action = decision_layer.decide(state)
|
||||
|
||||
# Assert
|
||||
assert action == "attack"
|
||||
```
|
||||
|
||||
## Pytest Tips
|
||||
|
||||
### Parametrize to Avoid Duplication
|
||||
```python
|
||||
import pytest
|
||||
|
||||
@pytest.mark.parametrize("health,expected", [
|
||||
(100, "idle"),
|
||||
(30, "flee"),
|
||||
(0, "dead"),
|
||||
])
|
||||
def test_state_by_health(health, expected):
|
||||
assert get_state(health) == expected
|
||||
```
|
||||
|
||||
### Use Fixtures for Shared Setup
|
||||
```python
|
||||
@pytest.fixture
|
||||
def mock_vision():
|
||||
return {"objects": ["enemy", "wall"], "confidence": 0.95}
|
||||
|
||||
def test_understanding_layer(mock_vision):
|
||||
result = understanding_layer.parse(mock_vision)
|
||||
assert "enemy" in result["threats"]
|
||||
```
|
||||
|
||||
## What to Test
|
||||
- ✅ Happy path (normal input)
|
||||
- ✅ Edge cases (empty, None, boundary values)
|
||||
- ✅ Error paths (invalid input raises expected exception)
|
||||
- ❌ Don't test implementation details — test behavior
|
||||
Reference in New Issue
Block a user