Backend testing strategies and test automation. Unit, integration, E2E, and load testing with best practices.
View on GitHubpluginagentmarketplace/custom-plugin-backend
backend-development-assistant
January 20, 2026
Select agents to install to:
npx add-skill https://github.com/pluginagentmarketplace/custom-plugin-backend/blob/main/skills/testing/SKILL.md -a claude-code --skill testingInstallation paths:
.claude/skills/testing/# Testing Skill
**Bonded to:** `testing-security-agent` (Secondary)
---
## Quick Start
```bash
# Invoke testing skill
"Write unit tests for my user service"
"Set up integration tests with database"
"Configure load testing with k6"
```
---
## Testing Pyramid
```
/\
/E2E\ Few, slow, expensive
/────\
/Integration\ Some, medium speed
/────────────\
/ Unit Tests \ Many, fast, cheap
/────────────────\
```
| Type | Coverage | Speed | Cost |
|------|----------|-------|------|
| Unit | 80%+ | Fast | Low |
| Integration | 60%+ | Medium | Medium |
| E2E | Critical paths | Slow | High |
---
## Examples
### Unit Test (pytest)
```python
import pytest
from unittest.mock import Mock
from app.services.user_service import UserService
class TestUserService:
@pytest.fixture
def service(self):
return UserService(db=Mock())
def test_get_user_returns_user(self, service):
service.db.get_user.return_value = {"id": 1, "name": "John"}
result = service.get_user(1)
assert result["name"] == "John"
service.db.get_user.assert_called_once_with(1)
def test_get_user_raises_when_not_found(self, service):
service.db.get_user.return_value = None
with pytest.raises(UserNotFoundError):
service.get_user(999)
```
### Integration Test
```python
import pytest
from fastapi.testclient import TestClient
from app.main import app
from app.database import get_db
@pytest.fixture
def client(test_db):
def override_get_db():
return test_db
app.dependency_overrides[get_db] = override_get_db
with TestClient(app) as c:
yield c
def test_create_and_get_user(client):
# Create user
response = client.post("/users", json={"email": "test@example.com"})
assert response.status_code == 201
user_id = response.json()["id"]
# Get user
response = client.get(f"/users/{user_id}")
assert response.status_code =