6

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?

5 Answers 5

15

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.

Sign up to request clarification or add additional context in comments.

3 Comments

The Group annotation will do nicely. Thanks.
I've set @group slow on all my slow tests and used a phpunit.xml file do exclude them by default. If I want to include them again I just run phpunit --no-configuration --group slow.
@dave1010 you can also use phpunit --exclude-group __no-group__; __no-group__ could be replaced by any random non-existent group name and the result would still be the same. Not to be confused with the real group, __nogroup__!
6

simply rename your method :

testFunctionality () { //blah }

to

ignore_testFunctionality () { //blah }

Comments

4

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.

1 Comment

Note that fixtures are still inserted for skipped tests which may be one of the slower parts of running tests
2

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 (in an apparent fork) 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.

3 Comments

Thanks for the research, I'd already done it but renaming the file isn't something I'm prone to do doing.
that are prefixed with . What is the prefix? A dot?
Yep, .. Revising the broken link too.
1

I prefer using normal names for my functions and put in the function docBloc

/** * @test */ public function getDetails() {} 

So, when I don't want this test to be run, I just remove that @test. Also, maybe you will find something useful here PHPUnit - The XML Configuration File I added in the "exclude" tag tests that I didn't want to be covered by phpunit.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.