当前位置: 首页 > 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

相关文章:

  • vim模式用法总结
  • 基于RK3588全高端智能终端机器人主板
  • 【论文阅读】MAG:一种用于航天器遥测数据中有效异常检测的新方法
  • MATLAB 嵌套switch语句||MATLAB while循环
  • C#,数值计算——插值和外推,分段线性插值(Linear_interp)的计算方法与源程序
  • MySQL索引:作用、类型、设计原则、优化策略与常见陷阱
  • python实现炫酷的屏幕保护程序
  • Three.js相机模拟
  • 数据结构 并查集
  • 9 HDFS架构剖析
  • 【Linux】线程互斥
  • 记GitLab服务器迁移后SSH访问无法生效的问题解决过程
  • 解决docker运行elastic服务端启动不成功
  • 记一次线上bug排查-----SpringCloud Gateway组件 请求头accept-encoding导致响应结果乱码
  • Netty源码学习4——服务端是处理新连接的netty的reactor模式
  • “寒冬”下的金三银四跳槽季来了,帮你客观分析一下局面
  • Android Volley源码解析
  • CSS实用技巧干货
  • Markdown 语法简单说明
  • Netty+SpringBoot+FastDFS+Html5实现聊天App(六)
  • Perseus-BERT——业内性能极致优化的BERT训练方案
  • Python语法速览与机器学习开发环境搭建
  • React-Native - 收藏集 - 掘金
  • socket.io+express实现聊天室的思考(三)
  • Spring Cloud(3) - 服务治理: Spring Cloud Eureka
  • SQLServer之索引简介
  • vue学习系列(二)vue-cli
  • win10下安装mysql5.7
  • 复习Javascript专题(四):js中的深浅拷贝
  • 基于axios的vue插件,让http请求更简单
  • 基于Mobx的多页面小程序的全局共享状态管理实践
  • 聊聊springcloud的EurekaClientAutoConfiguration
  • 扫描识别控件Dynamic Web TWAIN v12.2发布,改进SSL证书
  • 进程与线程(三)——进程/线程间通信
  • 浅谈sql中的in与not in,exists与not exists的区别
  • # 执行时间 统计mysql_一文说尽 MySQL 优化原理
  • #define 用法
  • #经典论文 异质山坡的物理模型 2 有效导水率
  • (1)SpringCloud 整合Python
  • (附源码)php新闻发布平台 毕业设计 141646
  • (附源码)spring boot基于小程序酒店疫情系统 毕业设计 091931
  • (附源码)springboot建达集团公司平台 毕业设计 141538
  • (黑马出品_高级篇_01)SpringCloud+RabbitMQ+Docker+Redis+搜索+分布式
  • (四)Controller接口控制器详解(三)
  • (译)2019年前端性能优化清单 — 下篇
  • .bat批处理(六):替换字符串中匹配的子串
  • .net 4.0发布后不能正常显示图片问题
  • .NET 8 中引入新的 IHostedLifecycleService 接口 实现定时任务
  • .NET MVC第五章、模型绑定获取表单数据
  • .NET 编写一个可以异步等待循环中任何一个部分的 Awaiter
  • .NET 将多个程序集合并成单一程序集的 4+3 种方法
  • .NET/C# 检测电脑上安装的 .NET Framework 的版本
  • .netcore 6.0/7.0项目迁移至.netcore 8.0 注意事项
  • .NET单元测试
  • .net开源工作流引擎ccflow表单数据返回值Pop分组模式和表格模式对比