Skip to main content
Testing is crucial for maintaining CVAT’s quality and reliability. This guide covers how to run existing tests and write new ones.

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:
  1. Ensure Docker is running
  2. Stop any existing CVAT instances that might use the same ports
  3. Install Python dependencies:
  1. 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

This command automatically:
  • 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:
This starts the containers but doesn’t run tests, allowing you to: Stop the services:

Running Frontend Tests

Unit Tests

CVAT uses Jest for frontend unit testing:
Run with coverage:
Run specific test files:
Run in watch mode:

Running E2E Tests

E2E tests use Cypress to test the complete application flow.

Interactive Mode

Open Cypress Test Runner:
This opens an interactive interface where you can:
  • 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:
Run specific test file:

E2E Test Configuration

Cypress configuration is in tests/cypress.config.js. Common settings:

Writing Tests

Writing Python REST API Tests

REST API tests are located in tests/python/rest_api/.

Test Structure

Using Fixtures

Common fixtures are defined in tests/python/shared/fixtures/:

Writing Frontend Unit Tests

Frontend tests use Jest and React Testing Library.

Component Test Example

Writing E2E Tests

E2E tests are in tests/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:
  1. Start test services:
  2. Make changes through the UI or API
  3. Backup the database:
  4. Backup data volume:
  5. Update JSON assets:

Test Coverage

Check test coverage for Python:
View coverage report:
For frontend coverage:

Debugging Tests

Python Tests

Add breakpoints:
Run with debug output:

Frontend Tests

Run in watch mode:
Use console.log or debugger statements.

Cypress Tests

Use interactive mode:
Add Cypress debug commands:

Continuous Integration

CVAT’s CI automatically runs:
  • All Python tests
  • Frontend unit tests
  • E2E tests
  • Linters and type checks
  • Security scans
Tests must pass before PRs can be merged.

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

  1. Write isolated tests: Each test should be independent
  2. Use descriptive names: Test names should clearly describe what they test
  3. Follow AAA pattern: Arrange, Act, Assert
  4. Test edge cases: Include tests for error conditions
  5. Keep tests fast: Mock external dependencies when possible
  6. Maintain test data: Keep test fixtures up to date
  7. Clean up: Ensure tests don’t leave side effects

Next Steps