簡體   English   中英

如何在PHPUnit中執行所有測試?

[英]How to execute all tests in PHPUnit?

我正在嘗試從我的測試套件運行所有測試,但是運行命令phpunit時PHPUnit找不到測試。 我在phpunit.xml中配置testsuite。

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);
    }
}

如果我運行phpunit通過文件測試, phpunit TestPage.php ,可以。

在此處輸入圖片說明

如您在文檔中所讀:

注意如果將PHPUnit命令行測試運行程序指向目錄,它將查找* Test.php文件。

最好使用這種格式的測試類。 但是,如果這不是您的選擇,則可以創建phpunit.xml文件並將其正確設置來更改此行為:

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

請注意,我刪除了* 從理論上講,phpunit應該遍歷該目錄並在文件末尾使用.php執行所有文件。

我認為,如果刪除*並設置正確的路徑,它應該可以工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM