tdd/tdd.rst
changeset 131 8888712bed39
parent 120 7428e411bd7a
equal deleted inserted replaced
130:e5d183dce985 131:8888712bed39
   523           del self.test_cases
   523           del self.test_cases
   524 
   524 
   525   if __name__ == '__main__':
   525   if __name__ == '__main__':
   526       unittest.main()
   526       unittest.main()
   527 
   527 
   528 Since we don't want to read this file into memory each time we run a
   528 Please note that although we highly recommend to write a docstring for
   529 separate test method, we will read all the data in the file into
   529 all the classes, functions and modules we have not done so to keep
   530 Python lists in the setUp method. The entire data file is kept in a
   530 above code compact and we have left it as an exercise for the you to
   531 list called test_cases which happens to be an attribute of the
   531 add them.
   532 TestGCDFunction class. In the tearDown method of the class we
   532 
   533 will delete this attribute to free up the memory and close the
   533 Coming back to tests themselves, since we don't want to read this file
   534 opened file.
   534 into memory each time we run a separate test method, we will read all
       
   535 the data in the file into Python lists in the setUp method. The entire
       
   536 data file is kept in a list called test_cases which happens to be an
       
   537 attribute of the TestGCDFunction class. In the tearDown method of the
       
   538 class we will delete this attribute to free up the memory and close
       
   539 the opened file.
   535 
   540 
   536 Our actual test code sits in the method which begins with the name
   541 Our actual test code sits in the method which begins with the name
   537 **test_** as said earlier, the test_gcd method. Note that we import
   542 **test_** as said earlier, the test_gcd method. Note that we import
   538 the gcd Python module we have written at the top of this test file and
   543 the gcd Python module we have written at the top of this test file and
   539 from this test method we call the gcd function within the gcd module
   544 from this test method we call the gcd function within the gcd module