Edgewall Software

Changes between Version 20 and Version 21 of TracDev/UnitTests


Ignore:
Timestamp:
Jan 8, 2016, 8:32:33 AM (8 years ago)
Author:
figaro
Comment:

Cosmetic changes

Legend:

Unmodified
Added
Removed
Modified
  • TracDev/UnitTests

    v20 v21  
    1 = Trac Unit Tests =
     1[[PageOutline(2-5,Contents,pullout)]]
    22
    3 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 still rather poor, and even if it were better, not having broken the unit tests does not mean you haven't broken the application! Unit tests do not replace manual testing.''
     3= Trac Unit Tests
    44
    5 Ideally, you'd also include new unit tests for a change or enhancement, even if you're 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.
     5Many 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 still rather poor, and even if it were better, not having broken the unit tests does not mean you haven't broken the application! Unit tests do not replace manual testing.
    66
    7 == Running the tests ==
     7Ideally, 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.
     8
     9== Running the tests
    810
    911You can run the unit tests from the command line by executing:
    10 {{{
     12{{{#!sh
    1113python -m trac.test --skip-functional-tests
    1214}}}
    13 or unix way:
    14 {{{
     15
     16or the Unix way:
     17{{{#!sh
    1518$ PYTHONPATH=. python trac/test.py --skip-functional-tests
    1619}}}
     20
    1721or:
    18 {{{
     22{{{#!sh
    1923$ make unit-test
    2024}}}
     
    2529
    2630This will run all the unit tests, but you can also run only those tests for a specific package or module. For example, to run the unit tests for the {{{trac.versioncontrol}}} package, execute:
    27 {{{
     31{{{#!sh
    2832python -m trac.versioncontrol.tests.__init__
    2933}}}
     34
    3035or if you prefer bash:
    31 {{{
    32  $ PYTHONPATH=. trac/versioncontrol/tests/__init__.py
     36{{{#!sh
     37$ PYTHONPATH=. trac/versioncontrol/tests/__init__.py
    3338}}}
    3439
    3540To run the unit tests for the {{{trac.versioncontrol.cache}}} module, execute:
    36 {{{
     41{{{#!sh
    3742python -m trac.versioncontrol.tests.cache
    3843}}}
    39 or
    40 {{{
    41  $ PYTHONPATH=. trac/versioncontrol/tests/cache.py
     44
     45or:
     46{{{#!sh
     47$ PYTHONPATH=. trac/versioncontrol/tests/cache.py
    4248}}}
    4349
    4450If 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:
    45 {{{
    46  $ find . -name *.pyc | xargs rm
     51{{{#!sh
     52$ find . -name *.pyc | xargs rm
    4753}}}
    4854
    49 === Test Database ===
    50 If you're developing on database different from SQLite, you may want to specify its URI using {{{TRAC_TEST_DB_URI}}} environment variable.
     55=== Test Database
    5156
     57If you are developing on a database different from SQLite, you may want to specify its URI using the {{{TRAC_TEST_DB_URI}}} environment variable.
    5258
    53 == Automatic builds ==
     59== Automatic builds
    5460
    5561The Trac unit tests are also run by the AutomaticBuilds.
    5662
    57 == Adding tests ==
     63== Adding tests
    5864
    5965If 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.
     
    6369Under WritingUnitTests you find a tutorial for writing your own unit tests.
    6470
    65 == Utility code for unit tests ==
     71== Utility code for unit tests
    6672
    6773The module [source:/trunk/trac/test.py#latest trac.test] contains a couple of functions and classes that can help writing unit tests. In particular, it provides an {{{InMemoryDatabase}}} class that can be used to test functionality that requires database access, without having to create an actual database on disk. Also there's a very simple factory for [http://c2.com/cgi/wiki?MockObject mock objects], which you can use to create quick substitutes of the "real" objects for testing.
    6874
    69 == Optional Dependencies ==
     75== Optional Dependencies
     76
    7077Some unit-tests depend on:
    7178 * [http://pytz.sourceforge.net/ pytz]
     
    7683
    7784These can be installed with easy_install:
    78 {{{
     85{{{#!sh
    7986easy_install pytz
    8087easy_install Pygments
     
    8491If these dependencies are not present, certain tests will be skipped.
    8592
    86 == Troubleshooting ==
     93== Troubleshooting
     94
    8795For general advice about Trac debugging, see TracTroubleshooting.
    8896
    89 === !ImportError: no module named tests ===
    90 If you try to run the tests and you receive
     97=== !ImportError: no module named tests
     98
     99If you try to run the tests and you receive the following message:
    91100{{{
    92101ImportError: No module named tests