温馨提示:本文翻译自stackoverflow.com,查看原文请点击:其他 - How to use only nth line of DataProvider in Codeception?
codeception dataprovider

其他 - 如何在Codeception中仅使用DataProvider的第n行?

发布于 2020-05-03 00:01:34

我正在使用Codeception进行测试。我正在使用数据提供程序,并且一切正常。但是我只能说“我只需要从数据提供者开始第1行”,我该怎么做?

    protected function pageProviderTest(){
        return[
            ['version' => 1],
            ['version' => 2],
            ['version' => 3],
        ];
    }

    /**
     * @param WebdriverTester $I
     * @dataProvider pageProviderTest
     */
    public function test1(WebdriverTester $I, Example $example){
        $I->see($example['version']);
    }


因此,例如,现在我只想测试测试是否看到“ 1”。我什至不想开始其他测试。

查看更多

提问者
Lukáš Secký
被浏览
12
Lukáš Secký 2020-03-13 18:04

所以我找到答案。您必须创建一个新的Example对象,并为其提供要使用的参数,因此在这种情况下,外观将类似于:

private $testingData;

public function __construct()
    {
   $this->testingData = new Example(pageProviderTest[0]); // enter the num of line in field
  }

 protected function pageProviderTest(){
        return[
            ['version' => 1],
            ['version' => 2],
            ['version' => 3],
        ];
    }

    /**
     * @param WebdriverTester $I
     * 
     */
    protected function test1(WebdriverTester $I, Example $example){
        $I->see($example['version']);
    }

  public function startTest(WebdriverTester $I){
   test1($I, $this->testingData);
  }