python-zx筆記11-測試壓力管理

來源:互聯網
上載者:User

標籤:tca   測試   16px   分享   運算   執行   tar   import   alt   

一、添加測試案例
calculator.pyclass Math:    def __init__(self,a,b):        self.a = int(a)        self.b = int(b)    def add(self):        return self.a + self.b    def sub(self):        return self.a - self.b
測試
test_Math.pyfrom caculator import *import unittestclass Test_add(unittest.TestCase):    def setUp(self):        print("Test is start")    def test_add(self):        j=Math(5,5)        self.assertEqual(j.add(),10)    def test_add1(self):        j=Math(10,20)        self.assertEqual(j.add(),30)    def tearDown(self):        print("test is end!")class Test_sub(unittest.TestCase):    def setUp(self):        print("Test is start")    def test_sub(self):        i=Math(8,8)        self.assertEqual(i.sub(),0)    def test_sub1(self):        i=Math(5,3)        self.assertEqual(i.sub(),2)        def tearDown(self):            print("test is end!")if __name__ == ‘__main__‘:    suite = unittest.TestSuite()    suite.addTest(Test_add("test_add"))    suite.addTest(Test_add("test_add1"))    suite.addTest(Test_sub("test_sub"))    #suite.addTest(Test_sub("test_sub1"))    runner = unittest.TextTestRunner()    runner.run(suite)
二、測試壓力執行順序

內建的順序:

import unittestclass Test2(unittest.TestCase):    def setUp(self):        print("Test1 start")    def test_c(self):        print("test_c")    def test_b(self):        print("test_b")    def tearDown(self):        print("test end")class Test1(unittest.TestCase):    def setUp(self):        print("Test2 start")    def test_d(self):        print("test_d")    def test_a(self):       print("test_a")    def tearDown(self):        print("Test2 end!")if __name__==‘__main__‘:    if __name__ == ‘__main__‘:        unittest.main()
//執行順序規則——測試類別或測試方法的數字與字母順序 0~9,A-Z

自訂順序:用測試集

三、用例綜合架構管理

 

前面測試案例與執行都是寫在一個檔案,當用例數量不斷增加的時候,用例的執行與管理變得非常麻煩,因此需要對用例根據具體的功能模組來使用單獨的模組來管理。就像一所學校要根據不同年級進行分班管理,也是同樣道理。

 

案例:Test_Project 檔案目錄下包含4個python檔案:

 

  • l--StartEnd.py—— SetUp與TearDown管理
  • l--calculatory.py——加減法運算方法的實現
  • l--test_add.py——加法測試案例
  • l--test_sub.py——減法測試案例
  • l--runtest.py——用例執行管理

 

python-zx筆記11-測試壓力管理

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.