Running one default testuite in PHPUnit

There are two test suites in my PHPUnit configuration file, unit and system . When I run the vendor/bin/phpunit test runner, it runs all the tests in both sets. I can target one package with the testsuite flag: vendor/bin/phpunit --testsuite unit , but I need to configure the test runner to run only the default unit set and run integration only when I make a special call with the testuite flag.

My configuration:

 <?xml version="1.0" encoding="UTF-8"?> <phpunit colors="true"> <testsuites> <testsuite name="unit"> <directory>tests/Unit</directory> </testsuite> <testsuite name="integration"> <directory>tests/Integration</directory> </testsuite> </testsuites> <filter> <whitelist> <directory suffix=".php">src</directory> </whitelist> </filter> <logging> <log type="coverage-clover" target="build/clover.xml"/> </logging> </phpunit> 
+8
php unit-testing phpunit
Jun 14 '16 at 19:05
source share
2 answers

There seems to be no way to list a few tests from the phpunit.xml file, but just run it. However, if you have some control over a more complete integration and test environment, where you can configure settings more precisely, you can have more than one phpunit configuration file and set one (or more) with more involved environments for setting the command line parameter --configuration <file> with a configuration that will do more. This at least ensures that the simplest configuration will work in the simplest way.

Two files can be called as you like if you run them on purpose, but it might be worth considering that the quick-launch file is called phpunit.xml by default, and the specially named and extended file is phpunit.xml.dist . The .dist file will automatically run by default if the original simple .xml does not exist . Another option is to have the phpunit.xml.dist file in the code repository, but then copy it to the phpunit.xml file with less "testuite", which itself is not checked in version control and is stored only locally. (it will probably also be marked as ignored in a .gitignore file or similar).

+1
Jun 14 '16 at 20:44
source share

Since PHPUnit 6.1.0 , the defaultTestSuite attribute is now supported.

See https://github.com/sebastianbergmann/phpunit/pull/2533

This can be used among other phpunit attributes, for example:

 <?xml version="1.0" encoding="UTF-8"?> <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.2/phpunit.xsd" backupGlobals="false" backupStaticAttributes="false" bootstrap="tests/bootstrap.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" defaultTestSuite="unit" processIsolation="false" stopOnFailure="false"> <testsuites> <testsuite name="unit"> <directory suffix="Test.php">tests/Unit</directory> </testsuite> <testsuite name="integration"> <directory suffix="Test.php">tests/Integration</directory> </testsuite> </testsuites> </phpunit> 

Now you can run phpunit instead of phpunit --testusite unit .

The name testuite may be case sensitive, so keep an eye out for this.

+4
Aug 01 '17 at 19:21
source share



All Articles