How to skip tests in PHPunit?

I am using phpunit in conjunction with jenkins and I want to skip certain tests by setting the configuration in phpunit.xml XML phpunit.xml

I know what I can use on the command line:

phpunit --filter testStuffThatBrokeAndIOnlyWantToRunThatOneSingleTest

how can I translate this to an XML file since the <filters> is only for code coverage?

I would like to run all tests except testStuffThatAlwaysBreaks

+63
php jenkins phpunit
Apr 20 2018-12-12T00:
source share
3 answers

The fastest and easiest way to skip tests that are either broken or you need to continue working, and just add the following to the top of your individual unit test:

 $this->markTestSkipped('must be revisited.'); 
+124
May 6 '12 at 18:19
source share
— -

If you can deal with ignoring the whole file, then

 <?xml version="1.0" encoding="UTF-8"?> <phpunit> <testsuites> <testsuite name="foo"> <directory>./tests/</directory> <exclude>./tests/path/to/excluded/test.php</exclude> ^------------- </testsuite> </testsuites> </phpunit> 
+25
Apr 20 '12 at 3:45
source share

It is sometimes useful to skip all tests from a specific file based on user conditions defined as php code. You can easily do this using the setUp function, in which makeTestSkipped also works.

 protected function setUp() { if ($yourCustomCondition) { $this->markTestSkipped('all tests in this file are invactive for this server configuration!'); } } 

$ yourCustomCondition can be passed through some method / property of a static class, a constant defined in the phpunit boot file, or even through a global variable - it's up to you.

+13
Feb 09 '16 at 9:44
source share



All Articles