Test Structure
CVAT has several test suites:- Python REST API tests:
tests/python/rest_api/ - Python SDK tests:
tests/python/sdk/ - Python CLI tests:
tests/python/cli/ - Frontend unit tests: In component directories
- E2E tests:
tests/cypress/e2e/
Prerequisites
Before running tests:- Ensure Docker is running
- Stop any existing CVAT instances that might use the same ports
- Install Python dependencies:
- Install Node.js dependencies:
Running Python Tests
REST API Tests
The REST API tests use pytest and run against a real CVAT instance in Docker containers.Run All Tests
- Starts all necessary Docker containers
- Runs the complete test suite
- Cleans up after completion
Run Specific Test Files
Run Specific Test Functions
Run with Verbose Output
Run Tests in Parallel
SDK Tests
CLI Tests
Keep Test Services Running
To keep the test environment running for debugging:- Access the test instance at http://localhost:8080
- Inspect the database
- Test API endpoints manually
Running Frontend Tests
Unit Tests
CVAT uses Jest for frontend unit testing:Running E2E Tests
E2E tests use Cypress to test the complete application flow.Interactive Mode
Open Cypress Test Runner:- Select specific tests to run
- Watch tests execute in real-time
- Debug failing tests
- See screenshots and videos
Headless Mode
Run all E2E tests in headless mode:E2E Test Configuration
Cypress configuration is intests/cypress.config.js. Common settings:
Writing Tests
Writing Python REST API Tests
REST API tests are located intests/python/rest_api/.
Test Structure
Using Fixtures
Common fixtures are defined intests/python/shared/fixtures/:
Writing Frontend Unit Tests
Frontend tests use Jest and React Testing Library.Component Test Example
Writing E2E Tests
E2E tests are intests/cypress/e2e/.
Cypress Test Example
Test Database
The test infrastructure uses a pre-populated database.Database Reset
The database is automatically restored after each test function to ensure test isolation.Updating Test Database
If you need to update the test database:-
Start test services:
- Make changes through the UI or API
-
Backup the database:
-
Backup data volume:
-
Update JSON assets:
Test Coverage
Check test coverage for Python:Debugging Tests
Python Tests
Add breakpoints:Frontend Tests
Run in watch mode:console.log or debugger statements.
Cypress Tests
Use interactive mode:Continuous Integration
CVAT’s CI automatically runs:- All Python tests
- Frontend unit tests
- E2E tests
- Linters and type checks
- Security scans
Troubleshooting
Port Conflicts
If test containers fail to start due to port conflicts:Database Issues
Recreate the test database:Test Failures
For date/time related failures, update JSON assets:Best Practices
- Write isolated tests: Each test should be independent
- Use descriptive names: Test names should clearly describe what they test
- Follow AAA pattern: Arrange, Act, Assert
- Test edge cases: Include tests for error conditions
- Keep tests fast: Mock external dependencies when possible
- Maintain test data: Keep test fixtures up to date
- Clean up: Ensure tests don’t leave side effects
Next Steps
- Review the architecture documentation
- Learn about the pull request process
- Check the code style guidelines