PHPUnit命令行测试工具是通过phpunit命令调用的。如下代码显示如何通过PHPUnit命令行测试工具运行测试。
phpunit ArrayTest PHPUnit 2.3.0 by Sebastian Bergmann. Time: 0.067288 OK (2 tests) |
phpunit --help PHPUnit 2.3.0 by Sebastian Bergmann. Usage: phpunit [switches] UnitTest [UnitTest.php] --coverage-data <file> Write code-coverage data in raw format to file. --coverage-html <file> Write code-coverage data in HTML format to file. --coverage-text <file> Write code-coverage data in text format to file. --testdox-html <file> Write agile documentation in HTML format to file. --testdox-text <file> Write agile documentation in Text format to file. --log-xml <file> Log test progress in XML format to file. --loader <loader> TestSuiteLoader implementation to use. --skeleton Generate skeleton UnitTest class for Unit in Unit.php. --wait Waits for a keystroke after each test. --help Prints this usage information. --version Prints the version and exits. |
<?xml version="1.0" encoding="UTF-8"?> <testsuites> <testsuite name="ArrayTest" tests="2" failures="0" errors="0" time="0.020026"> <testcase name="testNewArrayIsEmpty" class="ArrayTest" time="0.014449"/> <testcase name="testArrayContainsAnElement" class="ArrayTest" time="0.005577"/> </testsuite> </testsuites> |
<?xml version="1.0" encoding="UTF-8"?> <testsuites> <testsuite name="FailureErrorTest" tests="2" failures="1" errors="1" time="0.013603"> <testcase name="testFailure" class="FailureErrorTest" time="0.011872"> <failure message="" type="PHPUnit2_Framework_AssertionFailedError"></failure> </testcase> <testcase name="testError" class="FailureErrorTest" time="0.001731"> <error message="" type="Exception"></error> </testcase> </testsuite> </testsuites> --loader |
phpunit --skeleton Sample PHPUnit 2.3.0 by Sebastian Bergmann. Wrote test class skeleton for Sample to SampleTest.php. phpunit SampleTest PHPUnit 2.3.0 by Sebastian Bergmann. I Time: 0.007268 There was 1 incomplete test case: 1) testSampleMethod(SampleTest) OK, but incomplete test cases!!! Tests run: 1, incomplete test cases: 1. |
public function testSampleMethod( ) {} |