从PHP创建并运行代码接收测试

问题描述 投票:0回答:1

我知道Codeception专为命令行使用而设计。但是由于它完全基于PHP,所以我很确定必须有一种通过PHP动态/临时创建测试的方法。

就我而言,我正在从数据库获取验收测试步骤,需要使用Codeception动态运行测试。我希望有一种测试方法,而不必总是生成和删除临时测试文件夹并在命令行上运行代码接收命令。

问题是Codeception在创建cest时会动态生成一堆配置文件和脚本。我无法通过使用Codeception类使其工作。

有人知道实现这一目标的最佳方法是什么吗?

codeception
1个回答
0
投票

我认为最好的方法是实施https://codeception.com/docs/07-AdvancedUsage#Formats中记录的自定义测试加载器>

您仍然必须在每个套件中使用占位符文件来启动加载程序,但是可以从数据库中加载测试。

文档副本:

[除了标准测试格式(Cept,Cest,Unit,Gherkin)您可以实现自己的格式类以自定义测试执行。在套件配置中指定这些:

formats:
  - \My\Namespace\MyFormat

然后定义一个实现LoaderInterface的类

namespace My\Namespace;

class MyFormat implements \Codeception\Test\Loader\LoaderInterface
{
    protected $tests;

    protected $settings;

    public function __construct($settings = [])
    {
        //These are the suite settings
        $this->settings = $settings;
    }

    public function loadTests($filename)
    {
        //Load file and create tests
    }

    public function getTests()
    {
        return $this->tests;
    }

    public function getPattern()
    {
        return '~Myformat\.php$~';
    }
}

查看现有的Loader类以获取灵感:https://github.com/Codeception/Codeception/tree/4.0/src/Codeception/Test/Loader

© www.soinside.com 2019 - 2024. All rights reserved.