2.7 KiB
2.7 KiB
Testing Quick Start Guide
🚀 Get Testing in 5 Minutes
1. Prerequisites
- Docker installed and running
- Node.js 20+ (for local development)
- Make command available
2. Initial Setup
# Clone and navigate to project
cd vip-coordinator
# Copy environment variables
cp .env.example .env
# Edit .env and add your values (or use defaults for testing)
3. Run Your First Tests
Option A: Using Docker (Recommended)
# Run all tests
make test
# Run specific test suites
make test-backend # Backend only
make test-frontend # Frontend only
Option B: Local Development
# Backend tests
cd backend
npm install
npm test
# Frontend tests
cd ../frontend
npm install
npm test
4. Writing Your First Test
Backend Test Example
Create backend/src/routes/__tests__/health.test.ts:
import request from 'supertest';
import express from 'express';
const app = express();
app.get('/health', (req, res) => res.json({ status: 'ok' }));
describe('Health Check', () => {
it('should return status ok', async () => {
const response = await request(app).get('/health');
expect(response.status).toBe(200);
expect(response.body.status).toBe('ok');
});
});
Frontend Test Example
Create frontend/src/components/__tests__/Button.test.tsx:
import { render, screen } from '@testing-library/react';
import { Button } from '../Button';
describe('Button', () => {
it('renders with text', () => {
render(<Button>Click me</Button>);
expect(screen.getByText('Click me')).toBeInTheDocument();
});
});
5. Common Commands
# Database setup
make db-setup # Initialize test database
# Run tests with coverage
make test-coverage # Generate coverage reports
# Clean up
make clean # Remove all test containers
# Get help
make help # Show all available commands
6. VS Code Integration
Add to .vscode/settings.json:
{
"jest.autoRun": {
"watch": true,
"onStartup": ["all-tests"]
},
"vitest.enable": true,
"vitest.commandLine": "npm test"
}
7. Debugging Tests
# Run specific test file
npm test -- authService.test.ts
# Run in watch mode
npm run test:watch
# Debug mode
node --inspect-brk node_modules/.bin/jest --runInBand
8. Tips
- ✅ Run tests before committing
- ✅ Write tests for new features
- ✅ Keep tests simple and focused
- ✅ Use the provided fixtures and utilities
- ✅ Check coverage reports regularly
Need Help?
- See
TESTING.mdfor detailed documentation - Check example tests in
__tests__directories - Review
TESTING_SETUP_SUMMARY.mdfor architecture overview
Happy Testing! 🎉