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

ExcelBDD PHP Guideline

在PHP里面支持利用Excel的BDD,也支持利用Excel进行参数化测试

ExcelBDD

Use Excel file as BDD feature file, get example data from Excel files, support automation tests.

Features

The main features provided by this library are:

  • Read test data according to BDD from excel files.
  • Read test data according to Table from excel files.

Install

Install the library using composer Opens in new window or tab:

composer require excelbdd/excelbddorphp composer.phar require excelbdd/excelbdd

Excel BDD Tool Specification By ExcelBDD Method

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

Examples

Read Simple BDD data

The above is the simple BDD format for most usage.

<?php
use PHPUnit\Framework\TestCase;
use ExcelBDD\Behavior;final class BehaviorTest extends TestCase
{public static function BehaviorgetExampleListProvider(): array{$excelFile = "./BDDExcel/ExcelBDD.xlsx";$sheetName = "Sheet1";return Behavior::getExampleList($excelFile, $sheetName, "", "wrong");}/** @dataProvider BehaviorgetExampleListProvider */public function testBehaviorgetExampleList($ParamName1, $ParamName2, $ParamName3, $ParamName4){echo $ParamName1, $ParamName2, $ParamName3, $ParamName4, "\n";$this->assertSame(strpos($ParamName1, "V1"), 0);$this->assertSame(strpos($ParamName2, "V2"), 0);}
}

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


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");}

Input vs Expected

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);}

Read table data

<?php
use PHPUnit\Framework\TestCase;
use ExcelBDD\Behavior;
use PHPUnit\Framework\Attributes\DataProvider;final class BDDTest extends TestCase
{public static function TableDataProvider(): array{$excelFile = "../Java/src/test/resources/excelbdd/DataTable.xlsx";$sheetName = "DataTable2";return Behavior::getExampleTable($excelFile, $sheetName);}#[DataProvider('TableDataProvider')]public function testTableData($Header01, $Header02, $Header03, $Header04, $Header05, $Header06, $Header07, $Header08){echo $Header01, $Header02, $Header03, $Header04, $Header05, $Header06, $Header07, $Header08, "\n";$this->assertStringContainsString("Value1", $Header01);}
}

API

Behavior::getExampleList

public static function getExampleList(string $excelFile, string $sheetName = null, string $headerMatcher = null, string $headerUnmatcher = null): array

  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::getExampleTable

public static function getExampleTable($excelFile, $sheetName = null, $headerRow = 1, $startColumn = '`'): array

  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 auto detect

ExcelBDD PHP Guideline 线上版维护在 ExcelBDD PHP Guideline on Azure

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

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

相关文章:

  • C++静态链接库的生成以及使用
  • 【2024系统架构设计】 系统架构设计师第二版-未来信息综合技术
  • JavaFX修改软件图标
  • Linux ps -ef|grep去除 grep --color=auto信息
  • jQuery的学习(一篇文章齐全)
  • 注塑行业各类业务流程图(系统化)
  • Android Studio 安装及使用
  • 计算机网络的OSI七层模型
  • 如何一次性解压多个文件
  • 类和对象学习笔记
  • Linux程序之可变参数选项那些事!
  • 【1day】泛微e-office OA系统user_page接口未授权访问漏洞学习
  • Midjourney绘画提示词Prompt参考教程
  • Altium Designer学习笔记6
  • 【问题解决】Maven密码加密
  • vue3基于vite打包
  • 前端使用JWT时无法获取Authorization请求头
  • postman定义公共函数这样写,测试组长直呼牛逼!!!
  • 单元测试实战(六)其它
  • jmeter 主从配置
  • 4
  • C++ Day04 this指针,友元函数,重载
  • 2023做车载测试真的可以远离内耗!转行车载月入20K!
  • LINUXZ
  • C#单例模式懒汉式与饿汉式
  • 小微初创企业,如何利用媒体宣传快速成长
  • 【封装UI组件库系列】全局样式的定义与重置
  • opencv将32位深图片合成视频跳帧解决办法
  • 华为obs上传下载-Java版 2023-11-23
  • 2023年中国农业机器人行业市场规模及发展趋势分析[图]