Changes between Version 7 and Version 8 of TracDev/WritingUnitTests
- Timestamp:
- Jul 27, 2015, 8:53:35 PM (9 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
TracDev/WritingUnitTests
v7 v8 1 [[PageOutline( )]]1 [[PageOutline(2-5,Contents,pullout)]] 2 2 3 3 = Writing unit tests 4 4 5 This wiki page shows how to write your own unit tests for Trac or Trac plugin.5 This wiki page shows how to write your own unit tests for Trac or a Trac plugin. 6 6 7 7 == Start writing `TestCase`s 8 8 9 Any unit test should derive from class `unittest.TestCase` in order to be called from `unittest.makeSuite`. Thus you can make a set of test cases, which are called test suite.9 Any '''unit test''' should derive from class `unittest.TestCase` to be called from `unittest.makeSuite`. Thus you can make a set of '''test cases''', which are called '''test suite'''. 10 10 11 Usually you need to setup your `Environment` in orderto have any access to your Trac environment. This can be done using `EnvironmentStub`.11 Usually you need to setup your `Environment` to have any access to your Trac environment. This can be done using `EnvironmentStub`. 12 12 13 This test suite can be executed as a normal python code.13 This test suite can be executed as a normal Python code. 14 14 15 Here 's a simple Test case (from trac plugin [th:wiki/LogWatcherPlugin LogWatcherPlugin])to explain the above:15 Here is a simple test case from Trac plugin [th:wiki/LogWatcherPlugin LogWatcherPlugin] to explain the above: 16 16 17 17 {{{#!py … … 63 63 == Using several test methods 64 64 65 You can use several test methods within a `TestCase` class; they need to start with `test`. When you use method `setUp` it will be executed for each test method. If you only want to "set up" your test environment once ofyour test case, you need to use class method `setUpClass`.65 You can use several test methods within a `TestCase` class; they need to start with `test`. When you use method `setUp` it will be executed for each test method. If you only want to "set up" your test environment once for your test case, you need to use class method `setUpClass`. 66 66 67 67 Note that `setUpClass` and `tearDownClass` are available since Python 2.7.