← back to Designer Wallcoverings
DW-Agents/TESTING-QUICKSTART.md
216 lines
# Testing Quick Start Guide
## 5-Minute Setup
### 1. Install Dependencies
```bash
cd /root/Projects/Designer-Wallcoverings/DW-Agents
npm install
```
### 2. Run Your First Test
```bash
# Quick health check test (30 seconds)
npm run test:health
```
### 3. View Results
Look for output like:
```
PASS __tests__/health/health-check.test.ts
✓ should return 200 status code
✓ should respond within 1 second
...
Tests: 13 passed, 13 total
```
## Common Commands
```bash
# Run all tests
npm test
# Run specific suite
npm run test:health # Health checks only (fastest)
npm run test:unit # Unit tests only
npm run test:integration # Integration tests
npm run test:e2e # End-to-end tests
# Run with coverage
npm test -- --coverage
# Watch mode (re-run on changes)
npm run test:watch
# Interactive menu
./run-tests.sh
```
## Understanding Test Output
### Passing Test
```
✓ should return 200 status code (45ms)
```
- ✓ = Test passed
- (45ms) = Execution time
### Failing Test
```
✗ should return valid response
Expected: 200
Received: 500
```
- ✗ = Test failed
- Shows what was expected vs received
### Coverage Report
```
--------------------|---------|----------|---------|---------|
File | % Stmts | % Branch | % Funcs | % Lines |
--------------------|---------|----------|---------|---------|
All files | 85.23 | 76.45 | 82.11 | 85.67 |
```
- Shows what % of code is tested
- Target: >70% for all metrics
## Troubleshooting
### Tests Won't Run
```bash
# Problem: Dependencies not installed
npm install
# Problem: Wrong directory
cd /root/Projects/Designer-Wallcoverings/DW-Agents
# Problem: Permissions
chmod +x run-tests.sh
```
### Tests Timeout
```bash
# Increase timeout in .env.test
TEST_TIMEOUT=20000
```
### Service Not Available
```bash
# Check if master hub is running
curl http://localhost:9800/api/health
# Check PM2 services
pm2 list
# Verify port in .env.test
MASTER_HUB_PORT=9800
```
### All Tests Fail
```bash
# Check environment configuration
cat .env.test
# Verify BASE_URL
BASE_URL=http://localhost
# Check if services are running
pm2 status
```
## Quick Test Examples
### Test a Specific File
```bash
npm test -- __tests__/health/health-check.test.ts
```
### Test with Pattern
```bash
npm test -- --testNamePattern="health check"
```
### Run Single Test
```bash
npm test -- --testNamePattern="should return 200"
```
### Verbose Output
```bash
npm test -- --verbose
```
### Update Snapshots
```bash
npm test -- -u
```
## Performance Tests
```bash
# Run performance suite (takes 3-5 minutes)
npm test -- --testPathPattern=performance
# Expected output:
# - Response time baseline
# - Throughput metrics
# - Latency distribution (P50, P95, P99)
```
## CI/CD Integration
Tests run automatically on:
- Every push to main/develop
- Every pull request
- Nightly at 2 AM UTC
View results at:
```
https://github.com/your-org/DW-Agents/actions
```
## Next Steps
1. **Run health checks:** `npm run test:health`
2. **Check coverage:** `npm test -- --coverage`
3. **Review report:** `/tmp/improvements_test_engineer.md`
4. **Read full guide:** `README.test.md`
5. **Customize tests:** Add your own in `__tests__/`
## Quick Reference
| Command | What It Does | Time |
|---------|--------------|------|
| `npm run test:health` | Test health endpoints | ~30s |
| `npm run test:unit` | Test utilities | ~5s |
| `npm run test:integration` | Test API endpoints | ~45s |
| `npm run test:e2e` | Test full workflows | ~60s |
| `npm test -- --coverage` | Full suite + coverage | ~6m |
| `./run-tests.sh --smoke` | Quick smoke tests | ~30s |
## Help & Support
- **Full Documentation:** `README.test.md`
- **Detailed Report:** `/tmp/improvements_test_engineer.md`
- **Test Helpers:** `__tests__/helpers/`
- **Examples:** Look at existing test files
## Status Indicators
- ✓ **PASS** - Test passed successfully
- ✗ **FAIL** - Test failed (check output)
- ⊘ **SKIP** - Test skipped
- ⟳ **TODO** - Test marked as todo
## Coverage Goals
- **Minimum:** 70% all metrics
- **Good:** 80% all metrics
- **Excellent:** 90% all metrics
Current target: **70%** (enforced by CI/CD)
---
**Need help?** Check `README.test.md` or review test examples in `__tests__/`