Testing
The Haztrak project uses a combination of manual and automated testing to ensure that the application is thoroughly tested.
Contributors are encouraged to practice test driven development (TDD), we often ask that contributors provide tests to prove their PR are acting as intended.
Testing the Server
The test suite for each Django app
is located in the tests
directory of each app.
test files are ignored during the container build process.
The following links provide a good overview of testing within the Django, and DRF, ecosystems.
Pytest and Fixtures
To get started writing test for the server, you will need to be familiar with pytest.
As part of the effort to reduce test maintenance cost, the haztrak project has developed a series of
abstract factories as fixture. They are located in the conftest.py
files, which allows them to be
dependency injected into the test suite when requested by name.
For an introduction to using pytest fixtures to test django, see the following articles:
Running Server Tests
The client test suite can be run following these steps.
-
set up your development environment, (e.g., clone the repo, setup a virtual environment)
- Clone the repo
- Create a virtual environment
- Activate the virtual environment
- Download the dependencies
-
Run the tests
- To run all the test
pytest
- To run a specific test file or directory, just include the path to the test file or directory
pytest path/to/test.py
Testing the React Client
The Haztrak client employs an automated test suite with unit and integration tests to ensure the client is reliable and bug-free. These tests should be run locally by developers to ensure recent changes don't introduce errors as well during the CI process.
Tests are stored in *.spec.{ts,tsx}
files alongside the corresponding source file.
These files are ignored (not included) during the container build process.
Running Client Tests
The client test suite can be run following these steps.
-
Setup the dev environment
- Clone the repo
- Change into the client directory
- Download the dependencies
-
configure the environment
cp ../configs/.env.test ./.env
-
Run Tests
npm test