lidge-jun/codexclaw / plugins/codexclaw/skills/dev-testing
cxc-dev-testing
VerifiedUse for tests and release verification. Triggers: regression test, Playwright, E2E, contract test, coverage, CI flake, TDD, 테스트, 회귀 테스트, 품질 게이트.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 4.2 KB |
| agents/openai.yaml | config | 164 B |
| examples/console_logging.py | script | 1.1 KB |
| examples/element_discovery.py | script | 1.5 KB |
| examples/static_html_automation.py | script | 1.1 KB |
| references/acceptance-gates.md | markdown | 3.4 KB |
| references/acceptance-row-reachability.md | markdown | 1.1 KB |
| references/api-test-patterns.md | markdown | 3.4 KB |
| references/backend-testing.md | markdown | 4.3 KB |
| references/browser-testing.md | markdown | 3.5 KB |
| references/ci-integration.md | markdown | 1.3 KB |
| references/ci-pipeline.md | markdown | 8.5 KB |
| references/core/crud-test-matrix.md | markdown | 2.2 KB |
| references/edge-first-testing.md | markdown | 2.5 KB |
| references/limited-oracle-evaluation.md | markdown | 2.7 KB |
| references/load-testing.md | markdown | 6.9 KB |
| references/ml-evaluation.md | markdown | 7.2 KB |
| references/patch-integrity.md | markdown | 1.4 KB |
| references/property-and-mutation-testing.md | markdown | 652 B |
| references/tdd-and-regressions.md | markdown | 5.4 KB |
| references/test-oracle-integrity.md | markdown | 2.0 KB |
| references/test-strategy.md | markdown | 1.5 KB |
| scripts/with_server.py | script | 3.6 KB |
references/backend-testing.md
View on GitHub# Backend Testing Patterns
> Deep reference for `dev-testing` §2 Backend & API Testing.
## 1. Vitest Service Layer Pattern
```typescript
import { describe, it, expect, vi } from 'vitest';
import { InvoiceService } from '../src/services/invoice.service';
describe('InvoiceService.finalize', () => {
it('marks invoice paid and emits a domain event', async () => {
const repo = {
getById: vi.fn().mockResolvedValue({ id: 'inv_1', status: 'draft', amount: 5000 }),
save: vi.fn().mockResolvedValue(undefined),
};
const events = { publish: vi.fn().mockResolvedValue(undefined) };
const service = new InvoiceService({ repo, events });
const result = await service.finalize('inv_1');
expect(result.status).toBe('paid');
expect(repo.save).toHaveBeenCalledWith(expect.objectContaining({ status: 'paid' }));
expect(events.publish).toHaveBeenCalledWith('invoice.paid', expect.any(Object));
});
});
```
## 2. pytest Fixture Pattern
```python
import pytest
from unittest.mock import AsyncMock
from app.services.invoice_service import InvoiceService
@pytest.fixture
def repo():
fake = AsyncMock()
fake.get_by_id.return_value = {"id": "inv_1", "status": "draft", "amount": 5000}
return fake
@pytest.fixture
def events():
return AsyncMock()
@pytest.mark.asyncio
async def test_finalize_marks_invoice_paid(repo, events):
service = InvoiceService(repo=repo, events=events)
result = await service.finalize("inv_1")
assert result["status"] == "paid"
repo.save.assert_awaited_once()
events.publish.assert_awaited_once()
```
## 3. Database Testing with Testcontainers
### TypeScript
```typescript
import { PostgreSqlContainer } from '@testcontainers/postgresql';
let pg: Awaited<ReturnType<PostgreSqlContainer['start']>>;
beforeAll(async () => {
pg = await new PostgreSqlContainer('postgres:16-alpine').start();
process.env.DATABASE_URL = pg.getConnectionUri();
await runMigrations(process.env.DATABASE_URL!);
});
afterAll(async () => {
await pg.stop();
});
```
### Python
```python
import pytest
from testcontainers.postgres import PostgresContainer
@pytest.fixture(scope="session")
def pg_url():
with PostgresContainer("postgres:16-alpine") as container:
yield container.get_connection_url()
@pytest.fixture(scope="session", autouse=True)
async def migrated_db(pg_url):
await run_migrations(pg_url)
```
Use a real DB for migrations, transactions, unique constraints, foreign keys, ORM query translation, and pagination semantics.
## 4. API Harness Examples
### Supertest
```typescript
import request from 'supertest';
it('returns the shared error envelope', async () => {
const response = await request(app).post('/api/login').send({ email: 'bad' });
expect(response.status).toBe(400);
expect(response.body).toMatchObject({
success: false,
error: { code: 'VALIDATION_ERROR' },
meta: expect.any(Object),
});
});
```
### httpx
```python
@pytest.mark.asyncio
async def test_login_returns_shared_error_envelope(client):
response = await client.post('/api/login', json={"email": "bad"})
body = response.json()
assert response.status_code == 400
assert body["success"] is False
assert body["error"]["code"] == "VALIDATION_ERROR"
assert body["meta"]
```
## 5. Mock vs Real Decision Matrix
| Dependency | Preferred Choice | Why | Acceptable Fallback |
|------------|------------------|-----|---------------------|
| Pure domain helper | real | fast and deterministic | none needed |
| Repository during service test | fake / stub | isolate orchestration | framework mock |
| Real SQL behavior | Testcontainers DB | catches schema drift | in-memory DB only if semantics match |
| External HTTP API | recorded response / fake server | deterministic and cheap | mock adapter |
| Queue / pubsub boundary | fake adapter + retry assertions | verify interaction and payload | framework mock |
| Clock / UUID | fake clock / injected generator | stable determinism | monkeypatch |
## 6. Practical Rules
- Prefer factories over long inline objects.
- Keep fixtures local unless many tests truly share them.
- Roll back DB state between tests when possible.
- Assert machine-readable error codes, not only text messages.
- Pair backend API tests with contract verification when frontend depends on payload shape.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the work | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixes | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation code | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |