views:

265

answers:

3

I have a PHPUnit Test class that I'd like to be ignored from a test run. I know I can do it by renaming it so that it doesn't contain the word Test in its filename, but I'd rather not do that since it muddies up the source control waters more than I'd like.

Does anyone have a suggestion?

+1  A: 

I searched the entire PHPUnit manual and didn't find anything. You can ignore code for the purposes of test coverage, but that's about it. However, this ChangeLog mentions that it will "Ignore test file names that are prefixed with ." I haven't tried that, but it's worth a shot. Or you could comment out the test. I'm assuming you'd like something like NUnit offers where it will report the ignored tests; I didn't find anything like that.

TrueWill
Thanks for the research, I'd already done it but renaming the file isn't something I'm prone to do doing.
Allain Lalonde
+2  A: 

Hi,

There are a couple of options for the phpunit command that can help define which tests should and should not be run :

$ phpunit --help
PHPUnit 3.4.0beta5 by Sebastian Bergmann.

Usage: phpunit [switches] UnitTest [UnitTest.php]
       phpunit [switches] <directory>
...
  --filter <pattern>       Filter which tests to run.
  --group ...              Only runs tests from the specified group(s).
  --exclude-group ...      Exclude tests from the specified group(s).
  --list-groups            List available test groups.
...

Those will probably not allow to specify exactly what you wanted... But they might help.

For more details, see The Command-Line Test Runner


Especially, I kind of like the group feature : just use a @group tag in the phpdoc of your tests, to re-group them (for instance, one group per "chunk of functionnality") ; and, after, you can use the --group or --exclude-group options on the command line to specify which tests should or shouldn't be run.

In your case, if you cannot modify the tests, maybe the --filter option can help, depending on how your tests are nammed (ie, if there is a way to identify those you want to run) :

--filter
Only runs tests whose name matches the given pattern. The pattern can be either the name of a single test or a regular expression that matches multiple test names.


Another solution, if you are not always changing the "groups" of tests to run, might be to use a test-suite that only includes the tests you want to run.

For instance, take a look at Composing a Test Suite Using XML Configuration.

Pascal MARTIN
The Group annotation will do nicely. Thanks.
Allain Lalonde
You're welcome :-) Have fun !
Pascal MARTIN
+2  A: 

I realise this is an old question with an accepted answer, so I hope I'm not intruding, but I just wanted to point out for completion's sake that it's possible to skip tests. Incomplete and skipped tests aren't executed by PHPUnit.

Of course, that's on a per-test level - however, you can consolidate that by putting it into the class' setUp().

Just a heads-up.

pinkgothic
Neat idea. I'll keep it in mind.
Allain Lalonde