bddExcel for Python

2024-09-10 13:37:49 浏览数 (1)

本文介绍如何使用Python建立bddExcel实现BDD,注意bddExcel没有用到Cucumber。

1. 将bdd.xlsx放入项目主目录下

注意:Parameter Name暂时不支持中文

2. 建立普通测试文件

代码语言:javascript复制
#!/usr/bin/env python
#coding:utf-8
import unittest
from excelbdd import excelbdd
from parameterized import parameterized
from Account import MyAccoun
           
class ExcelBDDTest(unittest.TestCase):
    @parameterized.expand(excelbdd.get_example_list("bdd.xlsx"))    
    def test_get_example_tableB(self, HeaderName,初始余额, 存入额, 账户余额):
        account = MyAccoun()
        account.deposit(初始余额)
        account.deposit(存入额)
        assert account.getBalance(),账户余额
           
if __name__=="__main__":
unittest.main()

3. 完成产品代码

代码语言:javascript复制
#!/usr/bin/env python
#coding:utf-8
           
__metaclass_=type
class MyAccoun:
    def __init__(self):
        self.balance = 0.00
   
    def getBalance(self):
        return self.balance
           
    def deposit(self,value):    
        self.balance = self.balance   value
        return self.balance
      
    def withdraw(self,value):
        if (value>self.balance):
            return 0;
        else:
            self.balance = self.balance - value
            return self.balance 

0 人点赞