phpunit install and examples

piaoling  2013-03-19 14:20:57

1, make sure your system has pear

    if no, please go http://pear.php.net/manual/en/installation.getting.php to download and install, it has a guide to install.

2, after pear is installed and server is restarted.

    run pear config-set auto_discover 1

pear install pear.phpunit.de/PHPUnit

to install phpunit

3, download and install xdebug: http://xdebug.org/download.php

4, go to http://www.phpunit.de/manual/ to learn more about phpunit

5, magento test case example dowload:base code and examples


Test suit:


 <?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="BaseMagentoTest.php">
  <testsuites>
    <testsuite name="Checkout">
      <directory suffix="Test.php">../../app/code/local/Fly/Checkout/Test</directory>
    </testsuite>
    <testsuite name="Catalog">
      <directory suffix="Test.php">../../app/code/local/Fly/Catalog/Test</directory>
    </testsuite>
    <testsuite name="MagentoTest">
      <directory suffix="Test.php">..</directory>
    </testsuite>      
  </testsuites>
  <logging>
      <log type="coverage-html" target="F:/wamp/www/testResult/Report" charset="UTF-8"
           highlight="false" lowUpperBound="35" highLowerBound="70"/>
      <log type="json" target="F:/wamp/www/testResult/log/logfile.json"/>
      <log type="tap" target="F:/wamp/www/testResult/log/logfile.tap"/>
      <log type="junit" target="F:/wamp/www/testResult/log/logfile.xml" logIncompleteSkipped="false"/>
      <log type="testdox-html" target="F:/wamp/www/testResult/log/testdox.html"/>
      <log type="testdox-text" target="F:/wamp/www/testResult/log/testdox.txt"/>
  </logging>
  <php>
        <includePath>.;F:/wamp/bin/php/php5.3.13/pear</includePath>
      <ini name="foo" value="bar"/>
      <const name="foo" value="bar"/>
      <var name="foo" value="bar"/>
      <env name="foo" value="bar"/>
      <post name="foo" value="bar"/>
      <get name="foo" value="bar"/>
      <cookie name="foo" value="bar"/>
      <server name="foo" value="bar"/>
      <files name="foo" value="bar"/>
      <request name="foo" value="bar"/>
  </php>
</phpunit>                                                                                                
                                         


run the test suit: phpunit --verbose --configuration F:/wamp/www/magento1702/tests/phpunit/testsuite.xml

after run the code, you will get the test result on your screen and has log files, code coverage report.


run some test : phpunit --bootstrap F:/wamp/www/magento1702/tests/phpunit/BaseMagentoTest.php --coverage-html F:/wamp/www/testResult F:/wamp/www/magento1702/app/code/local/Fly/Checkout/Test/CheckutTest.php

after run the code, you will just get test result on your screen and code coverage report(like below pic).


test result log file(Tap style):

TAP version 13
ok 1 - CheckoutTest::testSoapCheckout
ok 2 - CheckoutTest::testArray
ok 3 - CatalogTest::testSoapCheckout
ok 4 - CatalogTest::testArray
ok 5 - MagentoTest::testBase
not ok 6 - Failure: MagentoTest::testCatalogCategoryModel
  ---
  message: 'Failed asserting that ''Root Catalog'' matches expected null.'
  severity: fail
  data:
      got: 'Root Catalog'
      expected: null
  ...
ok 7 - MagentoTest::testCatalogProductModel
1..7

类别 :  默认(751)  |  浏览(4183)  |  评论(0)
发表评论(评论将通过邮件发给作者):

Email: