1

I have a directory tests where I store all my tests.

Hierarchy of tests dirrectory

tests->
       ApplicationTests->
       IntegrationTests->
                         Factory->
                         Service->
       UnitTests->

How can I make phpunit launch tests only from for example Service directory, instead of the whole tests directory? I read about @Groups, but I think that's not what I'm looking for and it would be best if I would not need to edit config files, but some how, do it from the command line.

  • 1
    If you take a look around on the site you can also find some proposals and Q/A style discussion about this, e.g. https://stackoverflow.com/q/8313283/367456 , https://stackoverflow.com/a/7961097/367456 or even some basic explanation on the configuraiton: https://stackoverflow.com/q/19653958/367456 – hakre Jun 28 '21 at 19:53
  • @hakre Yeah I found similar solutions, to my problem, but I couldn't understand how could I use them. Only after I solved it myself, I understood, how it actually works. – Alpha Kenny Buddy Jun 29 '21 at 11:27
  • 1
    Yes, hopefully they add to the picture you start to see. What maybe triggered the search for those by me was, that in your answer you're referring to the test-suite (which is very fine btw.) and there is a more zero-conf approach, where you point to the folder of the tests you want to execute `./vendor/bin/phpunit --testdox tests/IntegrationTests/Server` for example. It's compatible with test-suites btw., so you can do the one or the other. So maybe organizing by folder is perhaps the foremost approach. – hakre Jun 29 '21 at 12:25

1 Answers1

1

Found a quite easy way, even with config editing.

phpunit.xml

See: The XML Configuration File Phpunit Docs and Organizing Tests Phpunit Docs<

<testsuite name="Service">
      <directory>tests/IntegrationTests/Service</directory>
</testsuite>

Command line: php ./vendor/bin/phpunit --testdox --testsuite Service

hakre
  • 193,403
  • 52
  • 435
  • 836