Testing and Coverage
Pytest
We use pytest
as our test runner.
It also supports Django unittest classes
You can check tests code in django_app/tests
# run tests
$ pytest django_app/tests/unittest --numprocesses 2
Tests Structure
django_app
├── conftest.py
├── tests
│ ├── integration # contains integration tests
│ └── unittest # contains unit tests
Integration Tests
Even you can use The test client
to make sure the Django view works as expected, it can not promise the Javascript can work with Django without issue.
That is why we need Integration Tests
in some cases.
In Django community, people usually choose selenium
, but in SaaS Hammer, I recommend people to use Playwright
instead.
Notes:
Playwright
is very fast, and supports multiple programming languages.Playwright
also supportsparallel testing
, which means, we can launchparallel testing
in the CI for shorter execution time.Playwright
has clean API, strong team and active community.SaaS Hammer
already import and configPlaywright
as our integration testing solution.
Coverage
We use pytest-cov
to help us collect coverage data and generate coverage report.