Unit Testing¶
Watcher includes comprehensive unit tests to ensure code quality and reliability. When contributing new features, you must include corresponding unit tests.
Test Coverage & Technologies¶
The test suite covers all 6 main modules of Watcher:
-
Back-End Tests: Python's standard unittest module
common/tests.pywatcher/tests.py- Module-specific test files for each component
-
Front-End Tests:
- Cypress specs for every page (
cypress/e2e/), with the API mocked
- Cypress specs for every page (
Automated CI/CD Testing¶
All tests are automatically executed in our CI/CD pipeline using GitHub Actions:
- Triggered on: Push, Pull Requests, and manual workflow dispatch
- Execution: Both back-end and front-end tests run automatically
- Coverage: Full test suite validation before code integration
The CI/CD workflow ensures that:
- No broken code reaches the main branch
- All new features are properly tested
You can view the workflow file at .github/workflows/docker-image-latest.yml and monitor test results in the Actions tab of the GitHub repository.
The commands¶
IMPORTANT: All test commands must be executed from the Watcher/Watcher directory:
cd Watcher/Watcher
Back-End Tests¶
To run all Django unit tests:
python manage.py test
To run tests for a specific module:
python manage.py test <module_name>
To run with verbose output:
python manage.py test --verbosity=2
Front-End Tests¶
The Cypress specs are fully mocked: they only need Watcher to answer on baseUrl (set in cypress.config.js, or pass --config baseUrl=http://localhost:9002), they read nothing from your database and need no account. The account they sign in with is not a secret: it is expose.testCredentials of cypress.config.js, read in the specs with Cypress.expose() (Cypress.env() is deprecated, and allowCypressEnv is false).
To run with an interactive Cypress Test Runner:
npm run cypress:open
To run in headless mode (CI/CD):
npm run test:e2e
Development Guidelines¶
Here is the file structure of the test files in Watcher:
Watcher/
├── common/
│ └── tests.py
├── watcher/
│ └── tests.py
├── [module_name]/
│ └── tests.py
└── cypress/
├── e2e/
└── support/
- For new modules, create a
tests.pyfile following Django's testing conventions. - For frontend features, add Cypress tests in the appropriate
cypress/e2e/directory.
When developing new features, ensure your tests cover:
- Happy path scenarios
- Edge cases
- Error handling
- Input validation
[IMPORTANT] All Pull Requests must include tests for new functionality. PRs without adequate test coverage may be rejected.