phpunit-testingphpunitdataprovider

Separate data provider from test case class


I want to use PHPUnit to test my PHP class.

Is it possible to put data providers for my test methods in a separate file created only for storing dataproviders? If so how to do that?

Another question is whether it's a good practice or perhaps it's better to keep test and data provider methods in the same test class.


Solution

  • Simply use @dataProvider class::method to use a method from a different class than the test case class as a data provider for a test.