How to filter for multiple tests in PHPUnit?

允我心安 提交于 2021-01-28 16:43:07

问题


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


回答1:


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.




回答2:


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




回答3:


I recommend usage of "spatie/phpunit-watcher" (https://github.com/spatie/phpunit-watcher) that will allow you to perform this type of filtering




回答4:


So I ended up creating my own configuration file with all the tests that I need and then pass it via --configuration to PHPUnit.




回答5:


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.



来源:https://stackoverflow.com/questions/50800071/how-to-filter-for-multiple-tests-in-phpunit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!