Skip to content

Testing

TreeQuest maintains testing strategies to ensure API, backend, and frontend stability.

CI/CD Pipeline Checks

Our GitHub Actions pipeline (.github/workflows/ci.yml) automatically enforces several quality gates on every push and pull request to the main branch:

  • Backend Tests: Spins up a temporary postgis service container and runs the full pytest suite.
  • Backend Linting: Uses ruff to enforce Python code formatting and catch static errors.
  • Frontend Typecheck: Runs TypeScript's tsc compiler to catch static type errors.
  • Frontend Linting: Validates code style and rules using ESLint.
  • Frontend Tests: Executes the unit and component test suite via npm test.

Backend Testing

The backend is built with FastAPI and utilizes pytest as its primary testing framework.

Test Structure

  • Unit Tests: Directed at isolating and testing specific services, models, and database repositories.
  • Integration Tests: There are integration test scripts (like test_api_trees.py) that use asynchronous httpx clients to test live API endpoints. These scripts simulate full user flows, such as:
    • Registering and logging in to obtain JWT access tokens.
    • Querying the core geospatial tree API with spatial bounds (lat, lon, radius).
    • Validating that the returned results are appropriately structured as GeoJSON FeatureCollections.

Running Tests

To run the Python backend tests:

cd backend
pytest

Note: Make sure to either mock database interactions or run against a local test PostGIS database to avoid modifying actual application data.

Frontend Testing

The React Native Expo frontend utilizes Jest paired with @testing-library/react-native for unit and component testing, alongside strict TypeScript static type-checking (tsc).

Test Structure

  • Stores & Logic (*.test.ts): Tests covering Zustand global state (authStore, progressStore, languageStore) and core functions.
  • Component & Screen Tests (*.test.tsx): Tests validating UI rendering and interactions for critical features like authentication (LoginScreen, RegisterScreen), map tools (MapFilterOverlay, QuestHUD), and gamification components.

Running Tests

To execute the Jest test suite:

cd frontend
npm run test

End-to-End (E2E) Testing with Maestro

We use Maestro for robust, resilient E2E mobile UI testing. Maestro automates actual user flows on an iOS simulator or Android emulator to ensure the app works correctly from a user's perspective.

Running Maestro Tests:

  1. Start the app with mocked data in one terminal:
    cd frontend
    EXPO_PUBLIC_MOCK_MODE=true npm run ios  # or android
    
  2. Run Maestro commands in another terminal:
    npm run maestro:test:login  # Run the login flow
    npm run maestro:test        # Run all test flows
    npm run maestro:validate    # Validate YAML flow definitions without starting a simulator
    

Test definitions (YAML files) are located in frontend/.maestro/flows/ and cover key journeys like logging in, filtering the map, submitting tree mockups, and exploring species details.