Edgewall Software

Changes between Version 23 and Version 24 of TracDev/UnitTests


Ignore:
Timestamp:
Jan 12, 2017, 11:11:42 PM (7 years ago)
Author:
Ryan J Ollos
Comment:

Put examples using make first.

Legend:

Unmodified
Added
Removed
Modified
  • TracDev/UnitTests

    v23 v24  
    33= Trac Unit Tests
    44
    5 Many of the Trac Python modules 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.
     5Most 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.
    66
    77Ideally, 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.
     
    99== Running the tests
    1010
    11 You can run the unit tests from the command line by executing:
     11You can run all of the unit tests from the command line using `make`:
     12
     13{{{#!sh
     14$ make unit-test
     15}}}
     16
     17or by invoking `python` directly:
     18
    1219{{{#!sh
    1320$ python -m trac.test --skip-functional-tests
     
    1926}}}
    2027
    21 or:
     28See FunctionalTests and apidoc:dev/testing for more details about functional tests.
     29
     30This assumes the current working directory is where you checked out the Trac code from the SubversionRepository.
     31
     32You can also run only the tests for a specific package, module, class or method.
     33For example, to run the unit tests for the `trac.versioncontrol` package, execute:
     34
    2235{{{#!sh
    23 $ make unit-test
     36$ make test=trac.versioncontrol.tests
    2437}}}
    2538
    26 See FunctionalTests and apidoc:dev/testing for more details about functional tests.
     39or:
    2740
    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:
    3141{{{#!sh
    3242$ python -m unittest trac.versioncontrol.tests.__init__
     
    3848}}}
    3949
    40 or:
     50To run the unit tests for the `trac.versioncontrol.cache` module, execute:
     51
    4152{{{#!sh
    42 $ make test=trac.versioncontrol.tests
     53$ make test=trac.versioncontrol.tests.cache
    4354}}}
    4455
    45 To run the unit tests for the `trac.versioncontrol.cache` module, execute:
     56or:
     57
    4658{{{#!sh
    4759$ python -m unittest trac.versioncontrol.tests.cache
     
    5365}}}
    5466
    55 or:
    56 
    57 {{{#!sh
    58 $ make test=trac.versioncontrol.tests.cache
    59 }}}
    60 
    6167To run the unit tests for the test class `trac.versioncontrol.tests.cache.CacheTestCase`, execute:
    6268{{{#!sh
    63 $ python -m unittest trac.versioncontrol.tests.cache.TestCase
     69$ python -m unittest trac.versioncontrol.tests.cache.CacheTestCase
    6470}}}
    6571
     
    6975}}}
    7076
    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:
     77If 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
    7279{{{#!sh
    73 $ find . -name *.pyc | xargs rm
     80$ make clean
    7481}}}
    7582
     
    7784
    7885{{{#!sh
    79 $ make clean
     86$ find . -name *.pyc | xargs rm
    8087}}}
    8188
     
    102109If 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.
    103110
    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.
     111For 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.
    105112
    106 Under WritingUnitTests you find a tutorial for writing your own unit tests.
     113WritingUnitTests is a tutorial for writing your own unit tests.
    107114
    108115== Utility code for unit tests