Changes between Version 113 and Version 114 of DeveloperGuidelinesTesting
- Timestamp:
- 08/08/11 21:23:22 (13 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
DeveloperGuidelinesTesting
v113 v114 79 79 * sloppy tests are as bad or worse than sloppy code - unit tests are not a silver bullet or a free lunch, 80 80 81 === Running unit tests === 81 === Test Runner === 82 83 [http://readthedocs.org/docs/nose/ nose] is a python module/command which finds and runs tests. nose is suitable as it has been widely adopted in the python community, allows standard test specifications and is highly configurable and customisable, without confusing "magical" behaviour. 82 84 83 85 Web2py imposes a severe problem on any external test runner, i.e. application code is provided a global environment by web2py, it must expect that environment. Therefore, the test runner must reproduce and provide that environment to the tests. This means that we can't use any external test runner that doesn't know about web2py. 84 85 [http://readthedocs.org/docs/nose/ nose] is a python module/command which finds and runs tests. nose is suitable as it has been widely adopted in the python community, allows standard test specifications and is highly configurable and customisable, without confusing "magical" behaviour. Documentation is [http://readthedocs.org/docs/nose/ here].86 86 87 87 To cope with web2py, a wrapper and a plugin has been written, which means that nosetests isn't run in the normal way, although we'll aim for that as much as possible. Extra arguments are just passed on to nose by the wrapper command, so the command's argument format is the same as that of the original nosetest command. … … 124 124 * Read this too: [http://ivory.idyll.org/articles/nose-intro.html] 125 125 126 === Examples ===126 === Running unit tests === 127 127 Assume our current directory is web2py/, which contains the applications folder. 128 128 129 129 To run all unit tests: 130 {{{ ./application/trunk/tests/nose.py }}} 130 {{{ 131 ./application/trunk/tests/nose.py 132 }}} 131 133 132 134 Currently these tests are stored in {{{/tests}}}. The nose plugin will look for tests in this folder. To select tests, give a file or folder path relative to the tests folder. 133 135 134 136 For example, there is a gis folder containing tests for the GIS mapping code. To run these particular tests: 135 {{{ ./application/trunk/tests/nose.py gis }}} 137 {{{ 138 ./application/trunk/tests/nose.py gis 139 }}} 136 140 137 141 Particular python version. Nose.py runs the tests with whichever python version ran it. It will use /usr/bin/python if run as an ordinary command as above. To select a different python version run (e.g. python 2.5): 138 {{{ /path/to/python2.5 ./application/trunk/tests/nose.py }}} 142 {{{ 143 /path/to/python2.5 ./application/trunk/tests/nose.py 144 }}} 139 145 140 146 This may be useful to test different versions but also installed modules. N.B. No testing has been done with virtualenv as of this time.