简体   繁体   中英

How to execute all tests in PHPUnit?

I'm trying run all tests from my testsuite, but PHPUnit not found the tests when I run command phpunit . I config testsuite in phpunit.xml.

phpunit.xml

<?xml version="1.0" encoding="UTF-8" ?>
<phpunit backupGlobals="true"
         backupStaticAttributes="false"
         bootstrap="./bootstrap.php"
         cacheTokens="false"
         colors="true"
         convertErrorsToExceptions="true"
         convertNoticesToExceptions="true"
         convertWarningsToExceptions="true"
         forceCoversAnnotation="false"
         mapTestClassNameToCoveredClassName="false"
         processIsolation="false"
         stopOnError="false"
         stopOnFailure="false"
         stopOnIncomplete="false"
         stopOnSkipped="false"
         strict="false"
         verbose="true">
    <testsuites>
        <testsuite name="All Tests">
            <directory suffix="*.php">.</directory>
        </testsuite>
    </testsuites>
</phpunit>

bootstrap.php

<?php

error_reporting(E_ALL | E_STRICT);
date_default_timezone_set('America/Sao_Paulo');
require_once(dirname(__FILE__) . '/WebTestCase.php');

WebTestCase.php

<?php

define('TEST_BASE_URL', 'http://localhost:8080');

class WebTestCase extends PHPUnit_Extensions_SeleniumTestCase
{

    protected function setUp() {
        $this->setBrowser('*firefox');
        $this->setBrowserUrl(TEST_BASE_URL);
        $this->setHost('localhost');
        $this->setTimeOut(30);
    }
}

TestPage.php

class TestPage extends WebTestCase
{

    public function testTitle()
    {
        $this->open("/");
        $title = $this->getTitle();
        $this->assertEquals('Home', $title);
    }
}

If I run phpunit passing file test, as phpunit TestPage.php , is ok.

在此处输入图片说明

As you can read in the documentation :

Note If you point the PHPUnit command-line test runner to a directory it will look for *Test.php files.

It is good practice to have your testing classes with this format. However, if that's not an option for you, you can change this behaviour creating the phpunit.xml file and setting it up properly:

<?xml version="1.0" encoding="utf-8" ?>
<phpunit>
<testsuite name='Name your suite'>
    <directory suffix=".php">/path/to/files</directory>
</testsuite>
</phpunit>

Note that I removed the * . In theory, phpunit should go through the directory and execute all files with .php at the end of the file.

I think that if you remove the * and set the correct path, it should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM