1. 程式人生 > >python - 資料驅動測試 - ddt

python - 資料驅動測試 - ddt

# -*- coding:utf-8 -*-

'''
@project: jiaxy
@author: Jimmy
@file: study_ddt.py
@ide: PyCharm Community Edition
@time: 2018-12-06 14:48
@blog: https://www.cnblogs.com/gotesting/

'''

'''

    study_ddt   :   data driver test , 資料驅動測試

1. 結合單元測試去執行用例
2. 裝飾器
3. 安裝:pip install study_ddt


如果使用了ddt設計了測試用例,載入測試用例時,可使用loader或discover

''' import unittest from ddt import ddt,data,unpack test_data = [{'a':1,'b':2},{'a':3,'b':4}] @ddt # 裝飾測試類 class TestDdt(unittest.TestCase): @data(test_data) # 裝飾測試方法 def test_001(self,item): print('item:',item) print(' ____-*-*-*-*-____') @data(*test_data) def test_002(self,item):
print('item:',item) print('item-a:',item['a']) print('item-b:',item['b']) print(' ____-*-*-*-*-____') @data(*test_data) @unpack # 對data拆分出來的資料,再次進行拆分,要用等量的變數進行接收 # 如果要拆分的物件是字典,用來接收資料的變數名必須跟key值保持一致,無序 def test_003(self,a,b): print('item-a',a)
print('item-b',b) print(' ____-*-*-*-*-____') if __name__ == '__main__': unittest.main()