1

I can't seem to find an answer to this anywhere, but it's probably right in front of me (usually is).

For my project: using PHPUnit, I have many tests, in several files, but there are a few tests that (deliberately) take a long time to run so I have them marked as 'skipped' by default.

What I'd like is a means to run ALL my tests (apart from the skipped tests) using the default command line instruction, but if the filter term is specifically for the skipped tests, then only those tests are run, (or they are included in the main run) and the skipped instruction is ignored.

I can achieve this if I can access the term used in --filter but I can't see if that's possible or not.

I'm aware that I could use test-suites and may well have to switch to that paradigm, but if it's possible not to, then I'd prefer that as it means I can use the default test command 99% of the time instead of having to specify the suite every time.

For reference I have my test command as an alias (to project\vendor\bin\phpunit), which makes for a fast instruction.

Unfortunately, setting a @group value and using that in the default alias ( project\vendor\bin\phpunit --exclude-group ), then using $ test --group doesn't work (the two parameters cancel each other out).

JamesBB
  • 418
  • 4
  • 7
  • If I understand the problem correctly, maybe [this](https://stackoverflow.com/questions/16061659/how-can-i-ignore-a-test-method-in-phpunit-without-modifying-its-content/16066969) approach will work – meewog Aug 06 '20 at 15:14
  • Unfortunately not. I want to be able to type `test` (which is aliased to /vendor/bin/phpunit') and have all my test (apart from a couple) run, as many times as I like, then type `test --filter OtherTests` which runs the tests previously skipped but that would only be used sparingly. – JamesBB Aug 06 '20 at 15:29
  • 1
    I'd go with the testsuite solution and add a second alias. Use test as default and something like testall to run the slower tests too. Then you type it out once and you will be fine. Having said that I feel like there might be some way to get the filter value in your test but it seems overly complicated for something that could be solved with test suites. – Dirk Scholten Aug 10 '20 at 08:58

1 Answers1

1

I guess the easiest way to do this, is to split your tests into two test suites. When you set defaultTestSuite attribute in your XML configuration, you don't have to specify the test suite when running your test command. If you want to run the other suite, you can do that by using the --testsuite option.

Here is a stripped-down example:

<?xml version="1.0" encoding="UTF-8"?>

<phpunit defaultTestSuite="unit" /* ... */>
    <testsuites>
        <testsuite name="unit">
            <directory>tests/Unit</directory>
        </testsuite>
        <testsuite name="functional">
            <directory>tests/Functional</directory>
        </testsuite>
    </testsuites>

    <!-- ... -->
</phpunit>
  • phpunit will run the unit test suite
  • phpunit --testsuite=functional will run the functional test suite
  • phpunit --testsuite=unit,functional will run both test suites
Philip Weinke
  • 1,804
  • 1
  • 8
  • 13