Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making PHPUnit ignore things?

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?

like image 529
Allain Lalonde Avatar asked Sep 12 '09 01:09

Allain Lalonde


2 Answers

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.

like image 54
Pascal MARTIN Avatar answered Oct 26 '22 02:10

Pascal MARTIN


simply rename your method :

testFunctionality () { //blah }

to

ignore_testFunctionality () { //blah }

like image 45
Mabrouk Avatar answered Oct 26 '22 02:10

Mabrouk