Unittestテストケーステストセットに追加された操作例


#coding=utf8 
'''
 sub
'''
import unittest
from source.calcutor import calculatorClass
class UpAndDown(unittest.TestCase):
    def setUp(self):
        ''' '''
        self.cal1=calculatorClass()
        self.cal2=calculatorClass(15,2)
    
    def test_sub_1(self):
        '''first is litter than second'''
        result=self.cal1.sub()
        self.assertTrue(result >0,"The result should be greater than 0")
        self.assertGreater(result, 0, "The result should be greater than 0")
        self.assertEqual(result,10,"The result should be equal 0")
        
    def test_sub_2(self):
        '''first is greater than second'''
        result=self.cal2.sub()
        self.assertTrue(result >0,"The result should be greater than 0")
        self.assertGreater(result, 0, "The result should be greater than 0")
        self.assertEqual(result,13,"The result should be equal 0")
        
    def tearDown(self):
        '''' '''
        del self.cal1,self.cal2
        
def suite_1():
    suite=unittest.TestSuite()
    ''' 1: '''
    suite.addTest(UpAndDown('test_sub_1'))
    suite.addTest(UpAndDown('test_sub_2'))
    
    
def suite_2():
    suite=unittest.TestSuite()
    ''' 2: '''
    tests=["test_sub_1","test_sub_2"]
    suite.addTests(tests)
    return suite

def suite_3():
    tests=["test_sub_1","test_sub_2"]
    ''' 3: '''
    suite=unittest.TestSuite(map(UpAndDown,tests))    
    return suite
            
if __name__=="__main__":
    unittest.TextTestRunner().run(suite_1())