From b11436bef0bd0a1ace7ff0ad876958125f8e69d2 Mon Sep 17 00:00:00 2001 From: Jan Romaniak Date: Thu, 3 Oct 2024 09:54:06 +0200 Subject: [PATCH 1/2] tests documentation --- docs/guide-dev/tests.md | 68 +++++++++++++++++++++++++++++------------ 1 file changed, 48 insertions(+), 20 deletions(-) diff --git a/docs/guide-dev/tests.md b/docs/guide-dev/tests.md index 48319d9..3fbe506 100644 --- a/docs/guide-dev/tests.md +++ b/docs/guide-dev/tests.md @@ -1,31 +1,59 @@ -# Run Test Suite +# Test Suite +The test suite is located within the tests directory and is organized into two subdirectories: unit and selenium. +The unit directory contains unit tests, which focus on testing individual components of the project in isolation. +The selenium directory contains tests that utilize Selenium for browser-based testing, +ensuring that the user interface and web interactions function as expected. ## Run "Unit" tests +Unit tests are executed within a Docker container using the pytest framework. +This ensures a consistent testing environment, isolated from local machine configurations. - docker compose run --rm backend \ - pytest \ - -n auto \ - -rP \ - --create-db \ - -p no:warnings \ - --cov-report= \ - --capture=sys \ - hct_mis_api/ tests/ + docker compose run --rm backend pytest -n auto --reruns 3 -rP -p no:warnings --cov-report= --capture=sys /tests/unit -#### Analyze HTML Report - - ... - ## Run "Selenium" functional test - ... - -#### Analyze HTML Report - ... +Selenium tests run on the host machine. +This is due to the fact that Selenium does not currently support the ARM64 architecture for Linux Docker images. +This will require some more steps to be taken before running the tests. +### Prerequisites +- pdm + +### Installation +1. **Services** + + To run the tests locally, the following services are required: + + 1. **Postgres** + 1. **Redis** + 1. **Elasticsearch** + + You can either install these services manually or use the `docker-compose` file located in the `development_tools` directory. + +1. **Running Services with Docker Compose** + + Make sure you have the required `.env` file from the backend setup, then you can run the services using the following command: + + ```bash + cd development_tools + docker compose --profile services up +1. Install system requirements + 1. MACOS + 1. `brew install wkhtmltopdf pango postgis gdal` +1. Crate virtual env + 1. `pdm venv create` +1. Register the created venv for the project with + 1. `pdm use` +1. Activate your venv + 1. `eval $(pdm venv activate)` +1. Check your environment + 1. eg. $`python --version` -> see that it uses Python 3.11.* +1. Install the packages + 1. `pdm sync --no-editable --no-self --no-isolation` +1. Run the tests + 1. `source ./development_tools/local_selenium_init.sh` + 1. `python -m pytest -svvv tests/selenium --html-report=./report/report.html` -## Combine coverage and display reports - ... From 697da2b4f892dce7ac88a1e3e75f95977cba50b2 Mon Sep 17 00:00:00 2001 From: Jan Romaniak Date: Fri, 4 Oct 2024 09:04:15 +0200 Subject: [PATCH 2/2] changed test dir inside docker --- docs/guide-dev/tests.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/guide-dev/tests.md b/docs/guide-dev/tests.md index 3fbe506..0763384 100644 --- a/docs/guide-dev/tests.md +++ b/docs/guide-dev/tests.md @@ -9,7 +9,7 @@ ensuring that the user interface and web interactions function as expected. Unit tests are executed within a Docker container using the pytest framework. This ensures a consistent testing environment, isolated from local machine configurations. - docker compose run --rm backend pytest -n auto --reruns 3 -rP -p no:warnings --cov-report= --capture=sys /tests/unit + docker compose run --rm backend pytest -n auto --reruns 3 -rP -p no:warnings --cov-report= --capture=sys ./tests/unit ## Run "Selenium" functional test @@ -54,6 +54,6 @@ This will require some more steps to be taken before running the tests. 1. `pdm sync --no-editable --no-self --no-isolation` 1. Run the tests 1. `source ./development_tools/local_selenium_init.sh` - 1. `python -m pytest -svvv tests/selenium --html-report=./report/report.html` + 1. `python -m pytest -svvv ./tests/selenium --html-report=./report/report.html`