I am able to run a single test from a suite using --filter
option.
I am wondering if there is a way to dynamically run multiple tests under the suite?
Thanks
A simple regex to filter for multiple tests could look like --filter '/test1|test2|test4/'
. This will match any tests which contain 'test1' 'test2' or 'test4' so for example test43 would be included, but test3 would not get run. The check is case-sensitive.
Work for me :
phpunit -c phpunit.dist.xml src --filter '/NameSpace\\UserBundle/|Namespace\\OtherBundle'
Do not work for me :
phpunit -c phpunit.dist.xml src --filter "/NameSpace\\UserBundle/|Namespace\\OtherBundle"
Whit double quote the result for me is "No tests executed!"
If you don't use \ in filter (for namespace) then double quote work perfectly but with namespace\bundle on my setup I need to use single quote.
The --filter option runs tests whose name matches the given regular expression pattern, so you should be able to select multiple tests by providing a suitable regular expression as argument.
See the documentation for the PHPUnit command line test runner
I recommend usage of "spatie/phpunit-watcher" (https://github.com/spatie/phpunit-watcher) that will allow you to perform this type of filtering
So I ended up creating my own configuration file with all the tests that I need and then pass it via --configuration
to PHPUnit.
You can also use the --group option.
You just need to add @group annotation to your methods like this:
/**
* @group test1
*/
public function test_example(){
...
Add @group to tests you want to run or group similar test into groups with the same @group name.
Run all tests that has a group with:
phpunit --group test1