在Python里面支持BDD
This tool is to get BDD test data from an excel file, its requirement specification is below
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.
pip install excelbdd
get_example_list(excelFile, sheetName = None, headerMatcher = None, headerUnmatcher = None)
get_example_table(excelFile,sheetName = None,headerRow = 1,startColumn = 'A')
The Famouse FizzBuzz kata is described in excelbdd format, as below.
import pytest
from excelbdd.behavior import get_example_list
import FizzBuzz
excelBDDFile = "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) == Output1
assert FizzBuzz.handle(Number2) == Output2
assert FizzBuzz.handle(Number3) == Output3
assert FizzBuzz.handle(Number4) == Output4
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.
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
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 Homepagehttps://dev.azure.com/simplopen/ExcelBDD