单元测试===单元测试用例基础!

#coding:utf-8
import unittest

def div(a,b):
    return a/b
    #1 / 2 = 1

class MyfristTestCase(unittest.TestCase):
    def setUp(self):
        print("run!")
    def tearDown(self):
        print("over!")
    def test_sample(self):
        print("test_sample")



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

 setUp的作用:在每个测试用例执行之前预置场景。比如,打开浏览器,截图,等等

tearDown的作用:在每个测试用例之后执行。比如:关闭浏览器,截图,记录等等

#coding:utf-8
import unittest

def div(a,b):
    return a/b
    #1 / 2 = 1

class MyfristTestCase(unittest.TestCase):
    def setUp(self):
        print("run!")
    def tearDown(self):
        print("over!")
    def test_sample(self):
        print("test_sample")
    def test_1_div_1(self):
        self.assertEqual(div(1,1),1/1)
    def test_3_div_4(self):
        self.assertEqual(div(3,4),3/4)
    def test_3_div_0(self):
        print("3/0")
        #assertRaises断言的方法,抛出异常的处理
        self.assertRaises(ZeroDivisionError,div,3,0)



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

 

posted @ 2017-08-29 20:57  AAA五金批发王建军  阅读(255)  评论(0编辑  收藏  举报