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

时间:2020-02-13 09:23:20

标签: codeception dataprovider

我正在使用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”。我什至不想开始的其他测试。

1 个答案:

答案 0 :(得分:0)

所以我找到了答案。 您必须制作一个新的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);
  }


相关问题