3.3 示例
檔案 demo.php:
<?php
class demo
public function subtract($a, $b)
}?>
測試用例:檔案 demotest.php:
<?php
require_once('phpunit/framework.php');
require_once(dirname(__file__). '/demo.php');
class demotest extends phpunit_framework_testcase
}?>
測試結果:
phpunit 3.4.14 by sebastian bergmann.
.time: 0 seconds, memory: 3.75mb
ok (1 test, 3 assertions)
3.4 示例
檔案 foo.php:
<?php
class foo
function formatn($num)
return $num;}}
?>
測試用例:檔案 footest.php:
<?php
require_once('phpunit/framework.php');
require_once(dirname(__file__). '/foo.php');
class footest extends phpunit_framework_testcase
//new乙個要測試的類為成員變數obj賦值
function setup()
//unset要測試的類
function teardown()
//自定義的testcase
function testformatn1()
function testformatn2()
function testformatn3()
function testformatn4()
function testformatn5()
function testformatn6()
function testformatn7()
function testformatn8()
function testformatn9()
function testformatn10()
function testformatn11()
function testformatn12()
function testformatn13()
}?>
測試結果:
phpunit 3.4.14 by sebastian bergmann.
.....f.......
time: 0 seconds, memory: 4.00mb
there was 1 failure:
1) footest::testformatn6
failed asserting that is true.
c:/program files/zend/apache2/htdocs/unit_test-2/footest.php:70
failures!
tests: 13, assertions: 13, failures: 1.
3.5 測試套件示例:
檔案 alltests.php:
<?php
require_once 'phpunit/framework.php';
require_once 'phpunit/textui/testrunner.php';
require_once 'demotest.php';
require_once 'footest.php';
class alltests
public static function main()
}?>
測試結果:
phpunit 3.4.14 by sebastian bergmann.
......f.......
time: 0 seconds, memory: 4.00mb
there was 1 failure:
1) footest::testformatn6
failed asserting that is true.
c:/program files/zend/apache2/htdocs/unit_test-2/footest.php:70
failures!
tests: 14, assertions: 16, failures: 1.
phpunit文件:
作者微博:
「十萬個為什麼」電腦學習網:
PHP 單元測試(PHPUnit) 2
3.3 示例 檔案 demo.php class demo public function subtract a,b 測試用例 檔案 demotest.php require once phpunit framework.php require once dirname file demo.php ...
PHP單元測試 PHPUnit安裝
phpunit 7.0 需要 php 7.1,強烈推薦使用最新版本的 php。phpunit 需要使用 dom 和 json 擴充套件,通常是預設啟用的。phpunit 還需要 pcre reflection spl 擴充套件。這些標準擴充套件預設啟用。覆蓋率分析報告功能需要 xdebug與 tok...
PHPUnit單元測試
單元測試 phpunit 定義乙個用來被測試的類remoteconnect author json class remoteconnect fp fsockopen servername,80 return fp?true false public function returnsampleobje...