Changes between Version 23 and Version 24 of TracDev/UnitTests
- Timestamp:
- Jan 12, 2017, 11:11:42 PM (7 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
TracDev/UnitTests
v23 v24 3 3 = Trac Unit Tests 4 4 5 M any of the Trac Python modulesare accompanied by unit tests. You should run the tests whenever making changes, to be confident you haven't broken anything. Note though that the coverage of application code by the unit tests is incomplete, so not having broken the unit tests does not mean you haven't broken the application! Unit tests do not replace manual testing.5 Most of the Python modules in the Trac codebase are accompanied by unit tests. You should run the tests whenever making changes, to be confident you haven't broken anything. Note though that the coverage of application code by the unit tests is incomplete, so not having broken the unit tests does not mean you haven't broken the application! Unit tests do not replace manual testing. 6 6 7 7 Ideally, also include new unit tests for a change or enhancement, even if you are just submitting a patch. Patches that break the unit tests are a lot less likely to get integrated than patches that add unit tests for the new or changed functionality. … … 9 9 == Running the tests 10 10 11 You can run the unit tests from the command line by executing: 11 You can run all of the unit tests from the command line using `make`: 12 13 {{{#!sh 14 $ make unit-test 15 }}} 16 17 or by invoking `python` directly: 18 12 19 {{{#!sh 13 20 $ python -m trac.test --skip-functional-tests … … 19 26 }}} 20 27 21 or: 28 See FunctionalTests and apidoc:dev/testing for more details about functional tests. 29 30 This assumes the current working directory is where you checked out the Trac code from the SubversionRepository. 31 32 You can also run only the tests for a specific package, module, class or method. 33 For example, to run the unit tests for the `trac.versioncontrol` package, execute: 34 22 35 {{{#!sh 23 $ make unit-test36 $ make test=trac.versioncontrol.tests 24 37 }}} 25 38 26 See FunctionalTests and apidoc:dev/testing for more details about functional tests. 39 or: 27 40 28 Assuming the current working directory is where you checked out the Trac code from the SubversionRepository.29 30 This will run all the unit tests, but you can also run only the tests for a specific package, module, class or method. For example, to run the unit tests for the `trac.versioncontrol` package, execute:31 41 {{{#!sh 32 42 $ python -m unittest trac.versioncontrol.tests.__init__ … … 38 48 }}} 39 49 40 or: 50 To run the unit tests for the `trac.versioncontrol.cache` module, execute: 51 41 52 {{{#!sh 42 $ make test=trac.versioncontrol.tests 53 $ make test=trac.versioncontrol.tests.cache 43 54 }}} 44 55 45 To run the unit tests for the `trac.versioncontrol.cache` module, execute: 56 or: 57 46 58 {{{#!sh 47 59 $ python -m unittest trac.versioncontrol.tests.cache … … 53 65 }}} 54 66 55 or:56 57 {{{#!sh58 $ make test=trac.versioncontrol.tests.cache59 }}}60 61 67 To run the unit tests for the test class `trac.versioncontrol.tests.cache.CacheTestCase`, execute: 62 68 {{{#!sh 63 $ python -m unittest trac.versioncontrol.tests.cache. TestCase69 $ python -m unittest trac.versioncontrol.tests.cache.CacheTestCase 64 70 }}} 65 71 … … 69 75 }}} 70 76 71 If you've made larger changes, then before running the tests, please make sure you've cleaned all {{{.pyc}}} files that may be left after removed or renamed source {{{*.py}}} files: 77 If you've made larger changes, before running the tests please make sure you've cleaned all `.pyc` files that may be left after removed or renamed source `*.py` files: 78 72 79 {{{#!sh 73 $ find . -name *.pyc | xargs rm80 $ make clean 74 81 }}} 75 82 … … 77 84 78 85 {{{#!sh 79 $ make clean86 $ find . -name *.pyc | xargs rm 80 87 }}} 81 88 … … 102 109 If you're adding a new module, or you want to add tests for a module that doesn't have any unit tests yet, you'll need to create a new Python module for the unit tests. 103 110 104 For example, say you want to add tests for the module {{{trac.foo}}} (which maps to {{{trac/foo.py}}}). You'll need to create a new module at {{{trac/tests/foo.py}}} and put the tests there. Also, you'll have to edit the {{{__init__.py}}} in the {{{tests}}}package so that your new unit tests get executed with the others.111 For example, say you want to add tests for the module `trac.foo` (which maps to `trac/foo.py`). You'll need to create a new module at `trac/tests/foo.py` and put the tests there. Also, you'll have to edit the `__init__.py` in the `tests` package so that your new unit tests get executed with the others. 105 112 106 Under WritingUnitTests you finda tutorial for writing your own unit tests.113 WritingUnitTests is a tutorial for writing your own unit tests. 107 114 108 115 == Utility code for unit tests