Python UT案例

'''
Created on 2012-9-12

filename:Rectangle.py

@author: nKF65624
'''

class Rectangle: 
    def __init__(self,length,width): 
        self.length = length 
        self.width = width 
         
    def girth(self): 
        return 2*(self.length+self.width) 
     
    def area(self): 
        return self.length*self.width 
       

 

 

 

'''

filename:pyTest.py
Created on 2012-9-12

@author: nKF65624
'''
from Rectangle import Rectangle 
import unittest 
 
class RectangleTestCase(unittest.TestCase): 
    def setUp(self): 
        self.rectangle = Rectangle(100,5)   
    
    def tearDown(self): 
        self.rectangle = None 
       
    def testClassObject(self):
        self.assertTrue(1, 1)
       
    def testGirth(self): 
        self.assertEqual(self.rectangle.girth(), 210) 
    
    def testArea(self): 
        self.assertEqual(self.rectangle.area(), 500) 
 

if __name__ == "__main__":    
    unittest.main()

你可能感兴趣的:(Python UT案例)