Testing Guide
This document provides a comprehensive guide to testing in the Rin project.
Overview
Rin uses different testing frameworks for the client and server:
- Client: Vitest with jsdom environment for React component testing
- Server: Bun's native test runner with in-memory SQLite database
Running Tests
All Tests
Client Tests
Server Tests
Test Structure
Client Tests
Location: client/src/**/__tests__/*.test.ts
Server Tests
Locations:
- Unit tests:
server/src/**/__tests__/*.test.ts - Integration tests:
server/tests/integration/*.test.ts - Security tests:
server/tests/security/*.test.ts
Writing Tests
Client Testing
- Component Tests: Test React components in isolation
- API Client Tests: Test the HTTP client and API calls
- Utility Tests: Test helper functions
Example:
Server Testing
- Service Tests: Test business logic in services
- Router Tests: Test API endpoints
- Utility Tests: Test helper functions
Example with database:
Test Fixtures
Server tests use fixtures for mock data:
server/tests/fixtures/index.ts- Mock database and environment setupserver/tests/test-api-client.ts- Type-safe API client for tests
Coverage
Both client and server support code coverage reporting:
Coverage reports are generated in:
- Client:
client/coverage/ - Server:
server/coverage/
CI/CD Integration
Tests run automatically on:
- Every push to
mainordevelopbranches - Every Pull Request
- Before deployment (blocking)
See GitHub Actions Workflows for details.
Best Practices
- Write tests for new features: Every new feature should include tests
- Test edge cases: Include tests for error conditions and boundary cases
- Use descriptive names: Test descriptions should clearly state what is being tested
- Keep tests independent: Each test should be able to run independently
- Mock external dependencies: Use mocks for external APIs and services
Troubleshooting
Client Tests Failing
Server Tests Failing
Coverage Not Generated
Make sure you have the coverage reporter configured in your test config.