Using the Python3 pytest and pytest-bdd packages, some testing of Domoticz has been automated.
Prevent regressions and maybe even do Behavior Driven Development where first the intended behavior gets described and second the test is used to validate it the implemention actually works as intended.
To describe the intended behavior the test are written in Gherkin syntax (Given, when, then)
The following Python packages have to be installed:
sudo apt install python3-pytest python3-pytest-bdd
To run the available BDD tests from the available feature files (from the Domoticz base directory):
pytest-3 -rA --tb=no test/gherkin/
The output will be something like the following:
=================================================================================================== test session starts ===================================================================================================
platform linux -- Python 3.8.10, pytest-4.6.9, py-1.8.1, pluggy-0.13.0
rootdir: /home/vagrant/domoticz
plugins: bdd-3.2.1
collected 3 items
test/gherkin/test_webserver.py ... [100%]
================================================================================================= short test summary info =================================================================================================
PASSED test/gherkin/test_webserver.py::test_compressedout
PASSED test/gherkin/test_webserver.py::test_uncompressedout
PASSED test/gherkin/test_webserver.py::test_decompressedout
================================================================================================ 3 passed in 0.14 seconds =================================================================================================
Some tests need specific testfiles to be present in the Domoticz environment. So run the following:
ln -s ../test/gherkin/resources/testwebcontent www/test
It will add a symbolic link to the Domoticz www directory called test pointing to some test web content used by the tests for validation purposes.
NOTE: This symbolic link can be removed after testing ofcourse.