在PHP里面支持利用Excel的BDD,也支持利用Excel进行参数化测试
Use Excel file as BDD feature file, get example data from Excel files, support automation tests.
The main features provided by this library are:
Install the library using composer Opens in new window or tab:
composer require excelbdd/excelbdd
or
php composer.phar require excelbdd/excelbdd
This tool is to get BDD test data from an excel file, its requirement specification is below
The above is the simple BDD format for most usage.
assertSame(strpos($ParamName1, "V1"), 0);
$this->assertSame(strpos($ParamName2, "V2"), 0);
}
}
testcase example is below, which uses headerMatcher to filter the data
public static function BDDSBTDataProvider(): array
{
$excelFile = "../Java/src/test/resources/excelbdd/ExcelBDD.xlsx";
$sheetName = "SBTSheet1";
return Behavior::getExampleList($excelFile, $sheetName, "Scenario");
}
#[DataProvider('BDDSBTDataProvider')]
public function testBDDSBTExampleList($ParamName1, $ParamName1Expected, $ParamName1TestResult, $ParamName2, $ParamName2Expected, $ParamName2TestResult, $ParamName3, $ParamName3Expected, $ParamName3TestResult, $ParamName4, $ParamName4Expected, $ParamName4TestResult)
{
echo "===testBDDSBTExampleList===", "\n";
echo $ParamName1, $ParamName1Expected, $ParamName1TestResult, $ParamName2, $ParamName2Expected, $ParamName2TestResult, $ParamName3, $ParamName3Expected, $ParamName3TestResult, $ParamName4, $ParamName4Expected, $ParamName4TestResult, "\n";
$this->assertSame(strpos($ParamName1, "V1"), 0);
$this->assertSame(strpos($ParamName2, "V2"), 0);
$this->assertSame($ParamName1TestResult,"pass");
}
ExcelBDD can detect 3 parameter-header patterns automatically, the last one is below.
public static function BDDExpectedDataProvider(): array
{
$excelFile = "../Java/src/test/resources/excelbdd/ExcelBDD.xlsx";
$sheetName = "Expected1";
return Behavior::getExampleList($excelFile, $sheetName);
}
#[DataProvider('BDDExpectedDataProvider')]
public function testBDDExpectedExampleList($ParamName1, $ParamName1Expected, $ParamName2, $ParamName2Expected, $ParamName3, $ParamName3Expected, $ParamName4, $ParamName4Expected)
{
echo "===testBDDSBTExampleList===", "\n";
echo $ParamName1, $ParamName1Expected, $ParamName2, $ParamName2Expected, $ParamName3, $ParamName3Expected, $ParamName4, $ParamName4Expected, "\n";
$this->assertSame(strpos($ParamName1, "V1"), 0);
$this->assertSame(strpos($ParamName2, "V2"), 0);
}
assertStringContainsString("Value1", $Header01);
}
}
public static function getExampleList(string $excelFile, string $sheetName = null, string $headerMatcher = null, string $headerUnmatcher = null): array
public static function getExampleTable($excelFile, $sheetName = null, $headerRow = 1, $startColumn = '`'): array
ExcelBDD PHP Guideline 线上版维护在 ExcelBDD PHP Guideline on Azure
ExcelBDD开源项目位于 ExcelBDD Homepagehttps://dev.azure.com/simplopen/ExcelBDD