当前位置: 首页 > news >正文

ExcelBDD Python指南

在Python里面支持BDD

Excel BDD Tool Specification By ExcelBDD Method

This tool is to get BDD test data from an excel file, its requirement specification is below

The Essential of this approach is obtaining multiple sets of test data, so when combined with Excel's Sheet, the key parameters are:

  1. ExcelFileName, required, which excel file is used.
  2. SheetName, optional, which Sheet the requirement writer writes in, if not specified, 1st sheet is chosen. An Excel file supports multiple Sheets, so an Excel is sufficient to support a wide range, such as Epic, Release, or a module.
  3. HeaderMatcher, filter the header row by this matcher, if matched, this set will be collected in.
  4. HeaderUnmatcher, filter the header row by this matcher, if matched, this set will be excluded.

Once the header row and parameter name column are determined by 'Parameter Name' grid automatically, the data area is determined, such as the green area in the table above. The gray area of the table above is the story step description, which is the general requirements step.

Install ExcelBDD Python Edition

pip install excelbdd

API

behavior.get_example_list

get_example_list(excelFile, sheetName = None, headerMatcher = None, headerUnmatcher = None)

  1. excelFile: excel file path and name, relative or absolute
  2. sheetName: sheet name, optional, default is the first sheet in excel file
  3. HeaderMatcher: filter the header row by this matcher, if matched, this set will be collected in. optional, default is to select all.
  4. HeaderUnmatcher: filter the header row by this matcher, if matched, this set will be excluded. optional, default is to exclude none.

behavior.get_example_table

get_example_table(excelFile,sheetName = None,headerRow = 1,startColumn = 'A')

  1. excelFile: excel file path and name, relative or absolute
  2. sheetName: sheet name, optional, default is the first sheet in excel file
  3. headerRow: the number of header row, optional, default is 1
  4. startColumn: the char of first data area, optional, default is column A in sheet

Simple example code

The Famouse FizzBuzz kata is described in excelbdd format, as below.

import pytest
from excelbdd.behavior import get_example_list
import FizzBuzzexcelBDDFile = "path of excel file" 
@pytest.mark.parametrize("HeaderName, Number1, Output1, Number2, Output2, Number3, Output3, Number4, Output4",get_example_list(excelBDDFile,"FizzBuzz"))
def test_FizzBuzz(HeaderName, Number1, Output1, Number2, Output2, Number3, Output3, Number4, Output4):assert FizzBuzz.handle(Number1) == Output1assert FizzBuzz.handle(Number2) == Output2assert FizzBuzz.handle(Number3) == Output3assert FizzBuzz.handle(Number4) == Output4

 Input vs Expect + Test Result Format - SBT - Specification By Testcase

 

testcase example is below, which uses headerMatcher to filter the data

@pytest.mark.parametrize("HeaderName, ParamName1, ParamName1Expected, ParamName1TestResult, \ParamName2, ParamName2Expected, ParamName2TestResult, ParamName3, \ParamName3Expected, ParamName3TestResult, ParamName4, ParamName4Expected, \ParamName4TestResult",get_example_list(bddFile1, "SBTSheet1","Scenario"))
def test_excelbdd_sbt(HeaderName, ParamName1, ParamName1Expected, ParamName1TestResult, ParamName2, ParamName2Expected, ParamName2TestResult, ParamName3, ParamName3Expected, ParamName3TestResult, ParamName4, ParamName4Expected, ParamName4TestResult):print(HeaderName, ParamName1, ParamName1Expected, ParamName1TestResult, ParamName2, ParamName2Expected, ParamName2TestResult, ParamName3, ParamName3Expected, ParamName3TestResult, ParamName4, ParamName4Expected, ParamName4TestResult)# add test data are loaded into the above parameters, add test code below

 ExcelBDD can detect 3 parameter-header patterns automatically, the last one is below.

Input vs Expected 

 

The demo code is below

@pytest.mark.parametrize("HeaderName, ParamName1, ParamName1Expected,  \ParamName2, ParamName2Expected, ParamName3, \ParamName3Expected, ParamName4, ParamName4Expected"get_example_list(bddFile1, "SBTSheet1","Scenario"))
def test_excelbdd_sbt(HeaderName, ParamName1, ParamName1Expected,  ParamName2, ParamName2Expected, ParamName3, ParamName3Expected, ParamName4, ParamName4Expected):print(HeaderName, ParamName1, ParamName1Expected, ParamName2, ParamName2Expected,  ParamName3, ParamName3Expected, ParamName4, ParamName4Expected)# add test data are loaded into the above parameters, add test code below

Get Table

The test data are organized in normal table, as below.

 the below code show how to fetch the test data into testcase

from excelbdd.behavior import get_example_table@pytest.mark.parametrize("Header01, Header02, Header03, Header04, Header05, Header06, Header07, Header08",get_example_table(tableFile, "DataTable4"))
def test_get_example_tableB(Header01, Header02, Header03, Header04, Header05, Header06, Header07, Header08):print(Header01, Header02, Header03, Header04, Header05, Header06, Header07, Header08)   # add test data are loaded into the above parameters, add test code below

ExcelBDD Python指南线上版维护在ExcelBDD Python Guideline

ExcelBDD开源项目位于 ExcelBDD Homepageicon-default.png?t=N7T8https://dev.azure.com/simplopen/ExcelBDD

 

http://www.lryc.cn/news/192075.html

相关文章:

  • 基于深度学习的驾驶员疲劳监测系统的设计与实现
  • B树、B+树详解
  • 使用hugging face开源库accelerate进行多GPU(单机多卡)训练卡死问题
  • IDEA 修改插件安装位置
  • 牛客网SQL160
  • HDFS Java API 操作
  • 论文阅读之【Is GPT-4 a Good Data Analyst?(GPT-4是否是一位好的数据分析师)】
  • 【数据结构】:二叉树与堆排序的实现
  • 纯css手写switch
  • PyTorch 深度学习之处理多维特征的输入Multiple Dimension Input(六)
  • LeetCode【438】找到字符串中所有字母异位词
  • 关于LEFT JOIN的一次理解
  • 各报文段格式集合
  • 【算法-动态规划】最长公共子序列
  • 区块链游戏的开发流程
  • 目标检测网络系列——YOLO V2
  • 15. Java反射和注解
  • pdf处理工具 Enfocus PitStop Pro 2022 中文 for mac
  • 微信小程序入门开发教程
  • php函数
  • 3.3 封装性
  • Redis魔法:点燃分布式锁的奇妙实现
  • iOS 项目避坑:多个分类中方法重复实现检测
  • 【003】EIS数据分析_#LIB
  • Sprint framework Day07:注解结合 xml 配置
  • LiveGBS流媒体平台GB/T28181功能-国标流媒体服务同时兼容内网收流外网收流多网段设备收流
  • js题解(四)
  • 如何进行大数运算和高精度计算?
  • 身份证读卡器跟OCR有何区别?哪个好?
  • 华为云云耀云服务器L实例评测 | 实例评测使用之硬件参数评测:华为云云耀云服务器下的 Linux 网络监控神器 bmon