Changes

From Gramps

Unit Test Quickstart

27 bytes added, 15:45, 24 November 2007
Simple Code Recipe
test module that may be considered something of a template.
<pre>import unittest
# import this test support utility before importing the module under test from test import test_util parent_dir = test_util.path_append_parent # enables the following import import MyModule
# look in test/test_util.py for other conveniences (and suggest more ideas) this_dir = test_util.abspath() data_dir = test_util.make_subdir("MyModule_test_data")
# unittest requires a TestCase class containing test function members # optional setUp() and tearDown() functions can perform pre/post test housekeeping class Test_top(unittest.TestCase):
def setUp(self): ... def tearDown(self): ...
def test_function_x(self): ..do stuff.. self.assertTrue(expression, "message to display on failure") #see other assert and fail functions in the unittest module
..more defs for more tests, more classes for possible grouping logic..
if __test__ == "__main__": unittest.main()</pre>
=== Using Your Unit Test ===

Navigation menu