Python-unittest简单使用之TestCase

【Python-unittest简单使用之TestCase】'''
Created on 2016-11-21
@author: One2Three
Project:最简单unittest框架使用
测试环境:Python3
'''

import unittest #定义测试类Test,父类为unittest.TestCase class Test(unittest.TestCase): """docstring for Test"""#重写父类setUp方法 def setUp(self): print("setUp")#定义测试用例,以“test_”开头命名的方法 def test_test1(self): print("test_test1") self.assertEqual('1','1',msg = '1=1')def test_test2(self): print('test_test2') self.assertEqual('1','2',msg = '1!=2')@unittest.skip('暂时跳过test_test3的测试') def test_test3(self): print('test_test2')#重写父类tearDown方法 def tearDown(self): print("tearDown")if __name__=='__main__': #unittest.main()方法会搜索该模块下所有以test开头的测试用例方法 unittest.main()

    推荐阅读