Automated Testing¶
Unit Testing¶
Unit testing is created using Pytest. Refer documentation closely to Pytest-Flask for this project.
conftest
conftest.py are a special file for pytest that is automatically loaded by pytest and typically contans fixtures and other setup code.
Docker Container Running
Make sure that you are running the docker container before doing any testing.
How to run unit tests?¶
Use the docker remote code execution
1 | |
or if you want to generate the coverage data
1 | |
Coverage File
This will produce a file called .coverage that contains the records and can be converted to reports.
Allure Results
Whenever you are running this tests, it will produce a folder called test_results that will contain results of the test. Refer below for more information about Allure.
How to get coverage report?¶
If you've run the tests using the above command and have .coverage file, you can generate the reports in multiple ways. More information in here.
1 | |
1 | |
What is .coveragerc file?
This file contains the configurations for the coverage testing.
Unit Testing in Pipelines¶
This was part of #12, but was cut out of scope. Some artefacts of the code can be seen here.
One particular one is the docker runtime.sh that can accomodate a APP_ENV=UNIT_TESTS to only run unit tests inside the docker.
Allure Report Generator¶
Allure Testing report is used as a tool to generate test report. More information here https://docs.qameta.io/allure/
This repo has a file called send_and_generate.py. It is a simple script that sends a test report to Allure and generates a report. This is currently integrated with the UWA System Health Lab Allure Setup. Documentation can be seen here.
Integration Testing¶
The integration tests are created with Cypress. This integration testing allows us to create frontend tests and obtain video or screenshots that can improve the quality of the test.
Running Tests Via Cypress IDE¶
Installment Prerequisite
- Install Nodejs and NPM (should be automatically installed with Nodejs).
- Go to
integration_testsfolder and donpm install. That is going to install yourpackage.jsonpackages.
- In one terminal, run
docker-compose upfor running application. - Without closing terminal opened in 1), open a new terminal and go to
/integration_testsand:- Run
yarn run cypress:openor - Run
npm run cypress:open
- Run
Note that by using this, the Cypress IDE will be running outside the docker container.
Configuring Cypress¶
Cypress configuration can be adjusted in the cypress.json file. If you want to define global varibles, this is the place to do it.
Global variables can be used in the code with Cypress.env('VAR').
More information can be seen in the official docs https://docs.cypress.io/guides/references/configuration
Writing Tests¶
There are 2 ways to create tests:
- By writing code tests, see Writing Test
- Or by using the Cypress Studio
Cypress studio makes it easy to create test by recording the user action through the Cypress IDE. Upon action of the user, Cypress studio writes codes in the tests which could be adjusted later for flexibility.
To use Cypress Studio Test Creation
Firstly, you need a test suite ends with .spec.js in the integration_tests/cypress/integration folder (either newly created from a test template or existing test).
Test Template
1 2 3 4 5 6 7 8 9 | |
- Select a test suite in the Cypress IDE to extend
- Hover on the test, and click the "magic wand" icon near the test
- Interact with the Cypress Web interface as if you are the test runner
- Save the test when you are done
- Modify the tests created by Cypress IDE as you need
Magic Wand Icon

Test files and directory organization¶
All test specs are located in integration_tests/cypress/integration. We recomend follow an structure by feature.
In integration_tests/cypress/support you can write reusable pieces of code for execute in all your tests with commands.
Test Results¶
Results after tests suite finished are stored in the following folders:
integration_tests/cypress/screenshots: Screenshots generated by cypressintegration_tests/cypress/videos: Videos generated by cypressintegration_tests/cypress/results: Allure formatted results
Allure Integration with Cypress¶
Cypress test runner has installed an allure plugin which is used to generate tests results with allure format.