A simple phpunit.xml configuration example 1


In case you don’t have one here is an example of a simple phpunit.xml configuration file. A best practice when using these files is to specify directory locations with the location of phpunit.xml as the include path. You can enforce this with the command line argument like so:

phpunit --configuration="location/of/tests/phpunit.xml" --include-path="location/of/tests/"

Hope this helps. Let me know if you have any questions setting up your file.

<?xml version="1.0" encoding="UTF-8"?>
<phpunit
     backupStaticAttributes="false"

     cacheTokens="false"
     colors="false"
     convertErrorsToExceptions="true"
     convertNoticesToExceptions="true"
     convertWarningsToExceptions="true"
     forceCoversAnnotation="false"
     mapTestClassNameToCoveredClassName="false"
     printerClass="PHPUnit_TextUI_ResultPrinter"

     processIsolation="false"
     stopOnError="false"
     stopOnFailure="false"
     stopOnIncomplete="false"
     stopOnSkipped="false"
     testSuiteLoaderClass="PHPUnit_Runner_StandardTestSuiteLoader"

     strict="false"
     verbose="false"
    >

    <testsuites>
        <testsuite name="AllTests">
        <directory>.</directory>
        </testsuite>
    </testsuites>

    <filter>
        <blacklist>
            <directory suffix=".php"></directory>
            <file></file>
            <exclude>
                <directory suffix=".php"></directory>
                <file></file>
            </exclude>
        </blacklist>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <directory suffix=".php"></directory>
            <file></file>
            <exclude>
                <directory suffix=".php"></directory>
                <file></file>
            </exclude>
        </whitelist>
    </filter>
</phpunit>

Josh Woodcock, PMI-ACP, Agile Coach


Leave a comment

Your email address will not be published. Required fields are marked *

One thought on “A simple phpunit.xml configuration example

  • Yuan Ruan

    In PHPunit documentation, I saw that :
    <>
    I have a phpunit.xml that same as:
    <<

    ../../../setup/src/*/*/Test/Unit

    >>
    I want to run this XML file without “–configurarion” argument, but the result was returned XML file content. I need to put “–configurarion” in command-line.
    Can you please explain to me why we must use “–configurarion” ? Because I think it can be automatically loaded configuration