【问题标题】:How to use only nth line of DataProvider in Codeception?如何在 Codeception 中仅使用第 n 行 DataProvider?
【发布时间】:2020-02-13 09:23:20
【问题描述】:

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

【问题讨论】:

    标签: codeception dataprovider


    【解决方案1】:

    所以我找到了答案。 你必须创建新的 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);
      }
    
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-05
      • 2020-10-06
      • 1970-01-01
      • 2014-02-28
      • 1970-01-01
      • 2017-09-10
      相关资源
      最近更新 更多