首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

python 单元测试示范2

2012-11-10 
python 单元测试示例2??#!/usr/bin/env pythonimport unittestclass CValue:test for run equaldef

python 单元测试示例2

?

?

#!/usr/bin/env pythonimport unittest;class CValue:    '''test for run equal'''    def __init__(self, nVal):        self.m_nVal = nVal;    def Equal(self, nVal):        if self.m_nVal == nVal:            return True;        return False;    def Multiple(self, nVal):        return 0 == self.m_nVal % nVal;class CValueTest(unittest.TestCase):    def __init__(self, strMethod):        #initilization parent        unittest.TestCase.__init__(self, strMethod);                print("init test case object!");        self.m_oVal = None;    def setUp(self):        self.m_oVal = CValue(100);    def tearDown(self):        print("end of test");    def testEqual(self):        self.assertEqual(True, self.m_oVal.Equal(100));        self.assertEqual(True, self.m_oVal.Equal(101));    def testMultiple(self):        print('test equal2');        self.assertEqual(True, self.m_oVal.Multiple(20));        self.assertEqual(False, self.m_oVal.Multiple(3));        self.assertEqual(True, self.m_oVal.Multiple(11));#create test collectiondef suite():    oSuite = unittest.TestSuite();    oSuite.addTest(CValueTest("testEqual"));    oSuite.addTest(CValueTest("testMultiple"));    return oSuite;    if "__main__" == __name__:    unittest.main(defaultTest = 'suite');

热点排行