Can phpunit use multiple data provider

前端 未结 5 750
渐次进展
渐次进展 2021-02-06 22:50

One question in short: can phpunit use multiple data provider when running test?

For example, I have a method called getById, and I need to run both successful and unsuc

5条回答
  •  爱一瞬间的悲伤
    2021-02-06 23:15

    You can use a helper function as shown below. The only problem is if the total number of test cases provided by all "sub data providers" is large, it can be tedious to figure out which test case is causing a problem.

    /** 
     * @dataProvider allIds
     */
    public function testGetByIdUnsuccess($id)
    {   
        $this->assertNull($this->model->getById($id));
    }  
    
    public function allIds()
    {
        return array_merge(provideInvalidId(),provideFailedId());
    }
    

提交回复
热议问题