Skip to content
This repository has been archived by the owner on Feb 5, 2024. It is now read-only.

Testing

Michiel edited this page Mar 9, 2023 · 17 revisions

Backend

Framework

Backend unit/integration test are done with the unittest framework. Because we work with docker, the tests needs to run in the docker. This can be done with following commands. It is of course necessary to first start the docker environment before running these commands.

  1. Run all tests: docker exec -it DrTrottoir-be python manage.py test

  2. Run one test file: docker exec -it DrTrottoir-be python manage.py test drtrottoir.tests.<TESTFILE>

  3. Run one test class: docker exec -it DrTrottoir-be python manage.py test drtrottoir.tests.<TESTFILE>:<TESTCLASS>

  4. Run a single test: docker exec -it DrTrottoir-be python manage.py test drtrottoir.tests.<TESTFILE>:<TESTCLASS>.<TESTMETHOD>

When all tests succeed, the coverage of the tests will also be showen in stdout. The coverage will be calculated for all the files in the Dr-Trottoir-2/drtrottoir directory. This can be edited in manage.pyand it is also possible to omit some files there. We use the coverage.py library for calculating the coverage of our tests in the backend.

Some usefull links:

It is possible to use the data in fixtures in your test, more info in the django documentation:

Dummy data

It is possible to populate the database with dummy data with fixtures. These fixtures are JSON or YAML files where you can put your dummy data.

The database can be populated with following command:

  • sudo docker exec -it DrTrottoir-be python manage.py loaddata fixtures/<filename>.json

To add more data, it is possible to manually add it to the init_data.json file or create your own .json file. When you already added the data into the database and want to extract it, you can do it with the following command:

  • sudo docker exec -it DrTrottoir-be python manage.py dumpdata drtrottoir --indent 4 > fixtures/<filename>.json

Some usefull links:

Frontend

Framework

We use 2 testing frameworks to test the frontend.

  1. For unit testing, we use Jest.
  2. For component and e2e testing, we can use cypress.

To run the Jest tests, you can run following command:

  • docker exec -it DrTrottoir-fe npm run test

The cypress tests are not yet possible to run in the docker due to some issues/errors. These tests can be ran locally (if they don't need the backend) with follow commands:

  • npm run cypress
  • npm run e2e
  • npm run e2e:headless
  • npm run component
  • npm run component:headless

ideally it will also be possible in the future to run these tests in the docker with the following command: docker exec -it DrTrottoir-fe <npm command>

Some usefull links:

Clone this wiki locally