2012-03-02 2 views
13
<phpunit backupGlobals="false" colors="true"> 
    <testsuite name="app1" > 
     <directory>./app1</directory> 
    </testsuite> 
    <testsuite name="app1" > 
     <directory>./app2</directory> 
    </testsuite> 
</phpunit> 

どのようにして最初のテストスイートと2番目のテストスイートが異なるブートストラップをロードできますか?PHPはすべてのtestuitに異なるブートストラップを付けます

答えて

2

できません。

PHPUnitでは、ブートストラップファイルを1つしか指定できないため、各テストスイートの各テストケースが実行される可能性があり、PHPUnitはブートストラップxmlから各テストスイートに "setup"ファイル。

phpunit 3.6で落胆させたTestSuiteクラスを使用すると、私の提案はbootstrap.phpの汎用ブートストラップコードをすべて実行するだけで、app1とあなたが継承しているApp1_TestCaseを持つapp2の

App1私は自分のテストとセットアップコードを持つ2つの別々のプロジェクトを持ち、1つのphpunitでそれらを実行しようとしないでください。

11

あなたは

<phpunit bootstrap="app2BootstrapFile.php" backupGlobals="false" colors="true"> 
    <testsuite name="app2" > 
     <directory>./app2</directory> 
    </testsuite> 
</phpunit> 

を実行するには二つの異なるブートストラップファイルと二つの異なる構成XMLファイル

app1.xml

<phpunit bootstrap="app1BootstrapFile.php" colors="true"> 
    <testsuite name="app1" > 
     <directory>./app1</directory> 
    </testsuite> 
</phpunit> 

app2.xmlを作成することができます。

あなたは(APP1言う)他のことをテストの一つより多く実行する場合は0
$phpunit --configuration app1.xml app1/ 
$phpunit --configuration app2.xml app2/ 

、私はユニット/統合テストでこれを行うのxml phpunit.xmlに名前を付けて、あなただけの

$phpunit app1/ 
$phpunit --configuration app2.xml app2/ 

を実行することができます。

+0

あなたが必要とする10種類のブートストラップファイルを持っているので、私は、これは良いアイデアだとは思いません、あなたのソリューションに基づいて、10のphpunitblabla.xmlファイルを作成する – smarber

13

私がしたことは、リスナーを持つことでした。

phpunit.xml

<?xml version="1.0" encoding="UTF-8"?> 
<phpunit bootstrap="./phpunit_bootstrap.php" 
    backupGlobals="false" 
    backupStaticAttributes="false" 
    verbose="true" 
    colors="true" 
    convertErrorsToExceptions="true" 
    convertNoticesToExceptions="true" 
    convertWarningsToExceptions="true" 
    processIsolation="false" 
    stopOnFailure="false" 
    syntaxCheck="true"> 
    <testsuites> 
     <testsuite name="unit"> 
      <directory>./unit/</directory> 
     </testsuite> 
     <testsuite name="integration"> 
      <directory>./integration/</directory> 
     </testsuite> 
    </testsuites> 
    <listeners> 
     <listener class="tests\base\TestListener" file="./base/TestListener.php"></listener> 
    </listeners> 
</phpunit> 

その後TestListener.php

class TestListener extends \PHPUnit_Framework_BaseTestListener 
{ 
    public function startTestSuite(PHPUnit_Framework_TestSuite $suite) 
    { 
     if (strpos($suite->getName(),"integration") !== false) { 
      // Bootstrap integration tests 
     } else { 
      // Bootstrap unit tests 
     } 
    } 
} 
関連する問題