Do PHPUnit ignore things?

I have a PHPUnit Test class that I would ignore from a test run. I know that I can do this by renaming it so that it does not contain the word Test in its name, but I would prefer not to do this, because it mixes the original control water more than I would like.

Does anyone have a suggestion?

+6
php unit-testing phpunit
source share
5 answers

There are several variations of the phpunit command that can help determine which tests should and should not 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 probably will not be able to indicate exactly what you wanted ... But they can help.

See Command Line Tester for more details.


In particular, I’m kind of like a group function: just use the @group tag in phpdoc of your tests to rearrange them (for example, one group into a “piece of functionality”); and after that you can use the --group or --exclude-group options on the command line to indicate which tests should or should not be performed.

In your case, if you cannot change the tests, perhaps the -filter option may help depending on how your tests are packed (that is, if there is a way to identify which ones you want to run):

--filter
Runs only those tests whose name matches the given pattern. A pattern can be either the name of a single test or a regular expression that matches multiple test names.


Another solution, if you do not always change the "groups" of tests to run, maybe use a test package that includes only those tests that you want to run.

For example, see Building a test case using an XML configuration .

+15
source share

just rename your method:

testFunctionality () {// blah}

to

ignore_ testFunctionality () {// blah}

+6
source share

I understand that this is an old question with an accepted answer, so I hope that I will not intrude, but I just wanted to point out that it is possible to skip tests . Incomplete and missed tests are not executed by PHPUnit.

Of course, at the level of each test, however, you can consolidate this by placing it in the setUp() class.

Just heads up.

+4
source share

I looked through the PHPUnit manual and found nothing. You can ignore the code for testing purposes, but more on that. However, this ChangeLog (in an explicit fork) mentions that it will “Ignore test file names with a prefix . “ I don’t know, ”t tried, but it's worth it. Or you can comment on the test. I assume you will like it something like NUnit suggestions where it will report ignored tests; I haven't found anything like it.

+1
source share

I prefer to use regular names for my functions and embed in the docBloc function

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

So, when I do not want this test to run, I just delete this @test. In addition, you might find something useful here PHPUnit - XML ​​configuration file I added “exclude” tags to the tags that I did not want to cover phpunit.

+1
source share

All Articles