Development

Changeset 19522

You must first sign up to be able to contribute.

Changeset 19522

Show
Ignore:
Timestamp:
06/24/09 21:57:30 (8 months ago)
Author:
fabien
Message:

[1.3] added --xml and --trace options to test:* tasks

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.3/WHATS_NEW

    r19273 r19522  
    211211    end(); 
    212212 
     213### JUnit Compatible XML Output 
     214 
     215The test tasks are now able to output a JUnit compatible XML file by using the 
     216`--xml` option: 
     217 
     218    $ php symfony test:all --xml=log.xml 
     219 
     220### Easy Debugging 
     221 
     222To ease the debugging when a test harness reports failed tests, you can now 
     223pass the `--trace` option to have a detailed output about the failures: 
     224 
     225    $ php symfony test:all -t 
     226 
    213227Tasks 
    214228----- 
  • branches/1.3/lib/autoload/sfCoreAutoload.class.php

    r19273 r19522  
    410410    'sfsymfonytesttask' => 'task/symfony/sfSymfonyTestTask.class.php', 
    411411    'sftestalltask' => 'task/test/sfTestAllTask.class.php', 
     412    'sftestbasetask' => 'task/test/sfTestBaseTask.class.php', 
    412413    'sftestcoveragetask' => 'task/test/sfTestCoverageTask.class.php', 
    413414    'sftestfunctionaltask' => 'task/test/sfTestFunctionalTask.class.php', 
  • branches/1.3/lib/task/symfony/sfSymfonyTestTask.class.php

    r18731 r19522  
    2727      new sfCommandOption('update-autoloader', 'u', sfCommandOption::PARAMETER_NONE, 'Update the sfCoreAutoload class'), 
    2828      new sfCommandOption('only-failed', 'f', sfCommandOption::PARAMETER_NONE, 'Only run tests that failed last time'), 
     29      new sfCommandOption('xml', null, sfCommandOption::PARAMETER_REQUIRED, 'The file name for the JUnit compatible XML log file'), 
    2930    )); 
    3031 
     
    105106    file_put_contents($statusFile, serialize($h->get_failed_files())); 
    106107 
     108    if ($options['trace']) 
     109    { 
     110      $this->outputHarnessTrace($h); 
     111    } 
     112 
     113    if ($options['xml']) 
     114    { 
     115      file_put_contents($options['xml'], $h->to_xml()); 
     116    } 
     117 
    107118    return $ret; 
    108119  } 
     120 
     121  // master is at sfTestBaseTask 
     122  /** 
     123   * @see sfTestBaseTask::outputHarnessTrace() 
     124   */ 
     125  protected function outputHarnessTrace(lime_harness $h) 
     126  { 
     127    $xml = new SimpleXMLElement($h->to_xml()); 
     128    foreach ($xml as $testsuite) 
     129    { 
     130      if ($testsuite['failures']) 
     131      { 
     132        $new = true; 
     133 
     134        foreach ($testsuite->testcase as $testcase) 
     135        { 
     136          foreach ($testcase->failure as $failure) 
     137          { 
     138            if ($new) 
     139            { 
     140              $this->log(''); 
     141              $this->log($this->formatter->format($testsuite['file'], 'ERROR')); 
     142              $new = false; 
     143            } 
     144 
     145            $this->log($this->formatter->format(sprintf('  at %s line %s', $testcase['file'], $testcase['line']), 'COMMENT')); 
     146            $this->log($this->formatter->format('  '.$testcase['name'], 'INFO')); 
     147            $this->log($failure); 
     148          } 
     149        } 
     150      } 
     151    } 
     152  } 
    109153} 
  • branches/1.3/lib/task/test/sfTestAllTask.class.php

    r18731 r19522  
    1717 * @version    SVN: $Id$ 
    1818 */ 
    19 class sfTestAllTask extends sfBaseTask 
     19class sfTestAllTask extends sfTestBaseTask 
    2020{ 
    2121  /** 
     
    2626    $this->addOptions(array( 
    2727      new sfCommandOption('only-failed', 'f', sfCommandOption::PARAMETER_NONE, 'Only run tests that failed last time'), 
     28    )); 
     29 
     30    $this->addOptions(array( 
     31      new sfCommandOption('xml', null, sfCommandOption::PARAMETER_REQUIRED, 'The file name for the JUnit compatible XML log file'), 
    2832    )); 
    2933 
     
    4044The task launches all tests found in [test/|COMMENT]. 
    4145 
    42 If one or more test fail, you can try to fix the problem by launching 
    43 them by hand or with the [test:unit|COMMENT] and [test:functional|COMMENT] task. 
     46If some tests fail, you can use the [--trace|COMMENT] option to have more 
     47information about the failures: 
     48 
     49    [./symfony test:all -t|INFO] 
     50 
     51Or you can also try to fix the problem by launching them by hand or with the 
     52[test:unit|COMMENT] and [test:functional|COMMENT] task. 
     53 
     54Use the [--only-failed|COMMENT] option to force the task to only execute tests 
     55that failed during the previous run: 
     56 
     57    [./symfony test:all --only-failed|INFO] 
     58 
     59Here is how it works: the first time, all tests are run as usual. But for 
     60subsequent test runs, only tests that failed last time are executed. As you 
     61fix your code, some tests will pass, and will be removed from subsequent runs. 
     62When all tests pass again, the full test suite is run... you can then rinse 
     63and repeat. 
     64 
     65The task can output a JUnit compatible XML log file with the [--xml|COMMENT] 
     66options: 
     67 
     68  [./symfony test:all --xml=log.xml|INFO] 
    4469EOF; 
    4570  } 
     
    83108    file_put_contents($statusFile, serialize($h->get_failed_files())); 
    84109 
     110    if ($options['trace']) 
     111    { 
     112      $this->outputHarnessTrace($h); 
     113    } 
     114 
     115    if ($options['xml']) 
     116    { 
     117      file_put_contents($options['xml'], $h->to_xml()); 
     118    } 
     119 
    85120    return $ret; 
    86121  } 
  • branches/1.3/lib/task/test/sfTestFunctionalTask.class.php

    r18731 r19522  
    1717 * @version    SVN: $Id$ 
    1818 */ 
    19 class sfTestFunctionalTask extends sfBaseTask 
     19class sfTestFunctionalTask extends sfTestBaseTask 
    2020{ 
    2121  /** 
     
    2727      new sfCommandArgument('application', sfCommandArgument::REQUIRED, 'The application name'), 
    2828      new sfCommandArgument('controller', sfCommandArgument::OPTIONAL | sfCommandArgument::IS_ARRAY, 'The controller name'), 
     29    )); 
     30 
     31    $this->addOptions(array( 
     32      new sfCommandOption('xml', null, sfCommandOption::PARAMETER_REQUIRED, 'The file name for the JUnit compatible XML log file'), 
    2933    )); 
    3034 
     
    4246The task launches all tests found in [test/functional/%application%|COMMENT]. 
    4347 
     48If some tests fail, you can use the [--trace|COMMENT] option to have more 
     49information about the failures: 
     50 
     51    [./symfony test:functional frontend -t|INFO] 
     52 
    4453You can launch all functional tests for a specific controller by 
    4554giving a controller name: 
     
    5059 
    5160  [./symfony test:functional frontend article comment|INFO] 
     61 
     62The task can output a JUnit compatible XML log file with the [--xml|COMMENT] 
     63options: 
     64 
     65  [./symfony test:functional --xml=log.xml|INFO] 
    5266EOF; 
    5367  } 
     
    8296      $h->register($finder->in($h->base_dir)); 
    8397 
    84       return $h->run() ? 0 : 1; 
     98      $ret = $h->run() ? 0 : 1; 
     99 
     100      if ($options['trace']) 
     101      { 
     102        $this->outputHarnessTrace($h); 
     103      } 
     104 
     105      if ($options['xml']) 
     106      { 
     107        file_put_contents($options['xml'], $h->to_xml()); 
     108      } 
     109 
     110      return $ret; 
    85111    } 
    86112  } 
  • branches/1.3/lib/task/test/sfTestUnitTask.class.php

    r18731 r19522  
    1717 * @version    SVN: $Id$ 
    1818 */ 
    19 class sfTestUnitTask extends sfBaseTask 
     19class sfTestUnitTask extends sfTestBaseTask 
    2020{ 
    2121  /** 
     
    2626    $this->addArguments(array( 
    2727      new sfCommandArgument('name', sfCommandArgument::OPTIONAL | sfCommandArgument::IS_ARRAY, 'The test name'), 
     28    )); 
     29 
     30    $this->addOptions(array( 
     31      new sfCommandOption('xml', null, sfCommandOption::PARAMETER_REQUIRED, 'The file name for the JUnit compatible XML log file'), 
    2832    )); 
    2933 
     
    4044The task launches all tests found in [test/unit|COMMENT]. 
    4145 
     46If some tests fail, you can use the [--trace|COMMENT] option to have more 
     47information about the failures: 
     48 
     49    [./symfony test:unit -t|INFO] 
     50 
    4251You can launch unit tests for a specific name: 
    4352 
     
    4756 
    4857  [./symfony test:unit strtolower strtoupper|INFO] 
     58 
     59The task can output a JUnit compatible XML log file with the [--xml|COMMENT] 
     60options: 
     61 
     62  [./symfony test:unit --xml=log.xml|INFO] 
    4963EOF; 
    5064  } 
     
    7791      $h->register($finder->in($h->base_dir)); 
    7892 
    79       return $h->run() ? 0 : 1; 
     93      $ret = $h->run() ? 0 : 1; 
     94 
     95      if ($options['trace']) 
     96      { 
     97        $this->outputHarnessTrace($h); 
     98      } 
     99 
     100      if ($options['xml']) 
     101      { 
     102        file_put_contents($options['xml'], $h->to_xml()); 
     103      } 
     104 
     105      return $ret; 
    80106    } 
    81107  } 
  • branches/1.3/test/other/fixtures/test/functional/result-harness.txt

    r6882 r19522  
    44Failed Test                     Stat  Total   Fail  List of Failed 
    55------------------------------------------------------------------ 
    6 fooActionsTest                     0      1      1  4 
     6fooActionsTest                     0      4      1  4 
    77Failed 1/2 test scripts, 50.00% okay. 1/8 subtests failed, 87.50% okay. 
  • branches/1.3/test/other/fixtures/test/result-harness.txt

    r6882 r19522  
    55Failed Test                     Stat  Total   Fail  List of Failed 
    66------------------------------------------------------------------ 
    7 tional/frontend/fooActionsTest     0      1      1  4 
     7tional/frontend/fooActionsTest     0      4      1  4 
    88Failed 1/3 test scripts, 66.67% okay. 1/9 subtests failed, 88.89% okay. 

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting.
Sensio Labs also supports several large Open-Source projects.