4,191
edits
Changes
→See also
{{languages|Unit Test Quickstart}}
=== First, some general procedural and structural notes ===
* the leading part of the test will commonly be named the same as the basename (or a variant) of the module under test, leading, for example, to the following files
* the test subdirectory can contain data or helper programs as required
{{stub}}
=== Running Unit Tests ===
A single unit test can be run from the top-level Gramps directory.
GRAMPS_RESOURCES=. python -m unittest <test_module>
for example:
GRAMPS_RESOURCES=. python -m unittest gramps.gen.lib.test.date_test
To run all the unit tests use:
GRAMPS_RESOURCES=. python -m unittest discover -p '*_test.py'
For verbose output use the -v flag:
GRAMPS_RESOURCES=. python -m unittest discover -p '*_test.py' -v
For convenience, all the unit tests can be run from the setup.py script using:
python setup.py test
For verbose output use:
python setup.py --verbose test
=== Simple Code Recipe ===
See also [[Testing Gramps]].
=== Further Information Mocking external dependencies with unittest.mock ===* other pages neededWhen you develop a class or a method with external dependencies, you often would like to provide test coverage just to the developed code proper, not the external dependencies it exercised. For instance, if your code calls sys.stderr.write, there is no need to check that sys.stderr.write actually outputs anything on the system standard error file descriptor. Rather, you'd like to know that you code calls the write method and what arguments get passed.* related topics** Python3.3 onwards provides the [[Programming_Guidelines#Pylint|Programming guidelines http://docs.python.org/dev/library/unittest.mock unittest.mock] module for such tasks. For Python 3.2 and earlier you can install the "mock" module that back- pylint]]* referencesports this functionality, tutorials, etc* available as "python-mock" package on Ubuntu or from [https://pypi.python.org/pypi/mock https://pypi.TBD.python.org/pypi/mock] Gramps tests using mocks will be skipped if the module is not available.
[[Category:Developers/Reference]]
[[Category:Developers/Quality Assurance]]