2010-10-29 141 views
0

我遇到的问题是我已经为我的Selenium/PHPUnit测试设置了运行程序,并且它们总是运行两次,每次测试一个接一个。然后它将进入下一个测试。我发现http://www.phpunit.de/ticket/688该错误似乎正是发生在我身上 - 所以我删除了所有对PHPUnit_MAIN_METHOD的引用,但我仍然有同样的问题,并且似乎“bug”在两年前解决了,而且我正在使用最新版本的PHPUnit。Selenium/PHPUnit测试总是运行两次,第二次失败

这里是我的亚军代码:

<?php 
require_once '/libs/prefix.php'; 

class WWW_TestSuite 
{ 
public static function main() 
{ 
    PHPUnit_TextUI_TestRunner::run(self::suite()); 
} 

public static function suite(){ 
    global $TEST_CASES, $TEST_FILES, $DOMAINS, $SUB_DOMAINS, $LOG_FILES; 
    $suite = new PHPUnit_Framework_TestSuite('PHPUnit Framework'); 
    $GLOBALS['testDomain'] = 'cco'; 
    $GLOBALS['startURL'] = 'www.domain.com'; 
    $GLOBALS['resultsFile'] = $LOG_FILES['www.domain.com']; 
    $numberOfTests = count($TEST_CASES['cco']); 
    $resultsFile = $GLOBALS['resultsFile']; 
    $fh = fopen($resultsFile, 'w'); 
    fwrite($fh, CRLF.DELIM_PLUS.CRLF); 
    fwrite($fh, $numberOfTests.NUMBER_OF_TESTS_STRING.CRLF); 
    fwrite($fh, DELIM_PLUS.CRLF); 
    fclose($fh); 
    foreach ($TEST_CASES['cco'] as $testCase){ 
     include $TEST_FILES['cco'][$testCase]; 
     $suite->addTestSuite($testCase); 
    } 
    return $suite; 
} 
} 
?> 

我的报告类代码:

<?php 
class reporting extends PHPUnit_Extensions_SeleniumTestCase 
{ 
private $linkNotFound; 
private $imageNotFound; 
private $textNotFound; 
private $testStatus; 
private $successLines = array(); 
private $errorLines = array(); 

public function testContentPresent($testContent, $className){ 
     foreach ($testContent as $contentType=>$contentArr){ 
      foreach ($contentArr as $currentContent){ 
       try { 
        $this->assertTrue($this->$contentType($currentContent)); 
        $this->successLines[] = $contentType.': '.$currentContent; 
       } catch (PHPUnit_Framework_AssertionFailedError $e) { 
        $this->textNotFound = 1; 
        $this->errorLines[] = $contentType.': '.$currentContent; 
       } 
      } 
     } 
    $this->print_report($this->testURL, $className, $this->errorLines, $this->successLines); 
} 


public function print_report($testURL, $testName, $errorLines='', $successLines=''){ 
    $timeStamp = CRLF.date("m/d/y h:i:s a").CRLF; 
    $resultsFile = $GLOBALS['resultsFile']; 
    $fh = fopen($resultsFile, 'a'); 
    fwrite($fh, CRLF.DELIM_NUM); 
    fwrite($fh, $timeStamp); 
    fwrite($fh, "TEST NAME: ".$testName.CRLF); 
    fwrite($fh, "TEST URL: ".$testURL.CRLF); 
    fwrite($fh, DELIM_NUM.CRLF); 
    if (!empty($successLines)) { 
     fwrite($fh, DELIM_STAR.CRLF); 
     fwrite($fh, TEST_PASS.CRLF); 
     fwrite($fh, DELIM_STAR.CRLF); 
     foreach ($successLines as $successLine){ 
      fwrite($fh, $successLine.CRLF); 
     } 
    }else { 
     fwrite($fh, DELIM_STAR.CRLF); 
     fwrite($fh, TEST_PASS.": NONE".CRLF); 
     fwrite($fh, DELIM_STAR.CRLF);   
    } 
    if (!empty($errorLines)) { 
     fwrite($fh, DELIM_STAR.CRLF); 
     fwrite($fh, TEST_FAIL.CRLF); 
     fwrite($fh, DELIM_STAR.CRLF); 
     foreach ($errorLines as $errorLine){ 
      fwrite($fh, $errorLine.CRLF); 
     } 
    }else { 
     fwrite($fh, DELIM_STAR.CRLF); 
     fwrite($fh, TEST_FAIL.": NONE".CRLF); 
     fwrite($fh, DELIM_STAR.CRLF); 
    } 
    fclose($fh); 
} 
} 
?> 

这里是正在使用的常量:

<?php 
// REPORT VARIABLES 
define('DELIM_NUM', '#################################################################################################'); 
define('DELIM_STAR', '***************************************************************'); 
define('DELIM_PLUS', '++++++++++++++++++++++++++++++++++++++++++++'); 
define('NUMBER_OF_TESTS_STRING', ' TESTS HAVE RUN IN THE FOLLOWING BATCH.'); 
define('CRLF' ,"\n"); 
define('TEST_PASS', "SUCCESSES"); 
define('TEST_FAIL', "ERRORS"); 

// DIRECTORY VARS 
define('CCO_TESTS_DIR', '/tests/CCO/'); 

// $DOMAINS - DOMAINS ARRAY 
$DOMAINS = array (
'cco' => '.domain.com' 
); 

// $SUB_DOMAINS - SUB DOMAINS ARRAY 
$SUB_DOMAINS = array (
'www', 
'dev2' 
); 

// $LOG_FILES - LOG FILE PATHS ARRAY 
$LOG_FILES = array (
'www.domain.com'    => CCO_LOG_FILES_DIR.date("m.d.y-H.i.s").'-CCO-WWW.txt' 
); 

// $TEST_CASES - TEST CASE NAMES ARRAY 
$TEST_CASES = array (
'cco' => array( 
    'CCO_TestName' 
) 
); 


// $TEST_FILES - ARRAY ASSOCIATING A TEST NAME WITH THE TEST FILE. 
$TEST_FILES = array ( 
'cco' => array (
    'CCO_TestName'    => CCO_TESTS_DIR.'CCO_TestName.php'      
    ) 
); 

// $TEST_NAME_URL_RELATION - ARRAY ASSOCIATING TEST CLASSES WITH THEIR ASSOCIATED URL ROOT. 
$TEST_NAME_URL_RELATION = array(
'cco'=>array(         
    'CCO_TestName'        => '/testdoc.asp?querystring=123'   
) 
); 

?> 

任何人都可以看到为什么这些测试会运行两次,并且第二次通过失败?

CLI输出的实例在运行测试:

CCO_TestName 
www.domain.com 
.www.domain.com 
E 

而且结果文件中只获取与第一次测试的结果进行更新(这是正常的行为,我们没有得到记录,如果我们在测试得到的E ,但我想知道为什么它被运行两次,首先

编辑: 忘了,包括我的安装文件:

<?php 
global $TEST_NAME_URL_RELATION; 
$testName = get_class($this);  
$this->reporting = new reporting(); 
$this->errorLines = array(); 
$this->startURL = $GLOBALS['startURL']; 
$this->setBrowser("*firefox"); 
$this->setBrowserUrl("http://".$this->startURL); 
$this->testUrlRoot = $TEST_NAME_URL_RELATION[$GLOBALS['testDomain']][$testName]; 
$this->testURL = $this->startURL.$this->testUrlRoot; 
print ($this->testURL."\n"); 
?> 

回答

3

的functi在

public function testContentPresent 
在我的报告类

是造成问题 - 硒自动运行,随着因此它被按实际试运行两次“测试”一词开头的方法。

更名为:

public function ContentPresent 

,它现在的作品。

+0

好找。任何机会你可以添加链接到Selenium文档有参考这个?绝对是一个很好的书签链接 – 2013-11-11 18:12:27

相关问题