Unit Tests
- Use Python and the
pytest
package to test our previously created functions.
- Run the tests through
VSCode
(in the Testing Menu) or the shell
.
- It primarily tests whether the function works as expected,
assert actual == expected
, rather than verifying the entire process's success.
- For better file organization, we may create a
tests
folder as a Python package (__init__.py
file) and put the unit tests (files and code) inside it.
Integration Tests
- Tests the whole flow and process, as we compare the actual and expected responses.
- Could use the
DeepDiff
Python library to compare 2 dictionaries (JSON documents).
- Run the tests through the
shell
.
- In the case of comparing decimal numbers, we could limit it to only a specific number of digits (e.g., 1 digit after the decimal point).
- For better file organization, we may create an
integration-tests
folder and put the integration tests (files and code) inside it.
- We may automate the integration test by creating a
.sh
file to:
- Change to a specific directory
- Run the
bash
command
- Set and export the environment variables
- Build the Docker image (could do so with a specific identifier using
DATE
in bash)
- Run the
docker-compose
file
- Run the integration test file
- Close (Down/Terminate) the
up
services in the docker-compose
file
- Return with a non-zero response in case of test fail (As it may return 0 even if the test fails, as the script finishes/is executed successfully)
Cloud Tests
- We’ll use
LocalStack
, a Python package, to test things locally (such as the cloud, e.g., AWS S3, AWS Kinesis, etc.) through Docker.
- It could be automated by appending it to the integration test folder and scripts.
Code Quality
PEP 8
- It’s a Python Enhancement Proposal that the Python community agreed on to follow some style guidelines in Python implementation.
- There’s also a Python package (Now called
pycodestyle
) to be used as a linter.
Linting