The PHPUnit command line testing tool is called through the phpunit command. The following code shows how to run tests through the PHPUnit command line testing tool.
phpunit ArrayTest
Time: 0.067288 OK (2 tests) |
For each test, the PHPUnit command line testing tool prints a character indicating the process:
·The test successfully prints ".".
·When running the test method, an assertion failure occurs and "F" is printed.
· When running the test method, an error occurs and "E" is printed.
·The test is not completed or the test does not print "I" (see the chapter "Unfinished Tests" at the end of this book).
PHPUnit can distinguish between failures and errors. A failure is a PHPUnit assertion violation, and an error is an unexpected exception or a PHP error. Sometimes this distinction is useful because mistakes are easier to fix than failures. If you have a long list of issues, it's a good idea to resolve all the errors first and then see if any failures remain.
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. |
Let’s take a look at some of the following code command line testing tool options:
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. |
phpunit UnitTest
Run the test provided by the class UnitTest, which should be defined in the source file UnitTest.php.
The class UnitTest must inherit the PHPUnit2_Framework_TestCase class, or provide a public static method suite and return a class of the PHPUnit2_ Framework_Test object (for example, an instance of the class PHPUnit2_Framework_TestSuite)
phpunit UnitTest UnitTest.php
<?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> |
<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> |
The following XML log file is generated for two tests of the test class named FailureErrorTest, one is testFailure and the other is testError. This shows how failures and errors are represented separately.
<?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 |
<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
Specifies the test suite loader to be used.
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. |
The standard test suite loader will look for source files in the current working directory and the path defined by PHP's include_path configuration directive. According to the naming rules of PEAR, the source file mapped to a class name in the form Project_Package_Class is Project/Package/Class.php.
--skeleton
public function testSampleMethod( ) {} |
A framework that generates a test case class named UnitTest (in the file UnitTest.php) for the class Unit (in the file Unit.php). For each method of the original class, an unfinished test case is provided in the generated test case class (see the "Unfinished Tests" section at the end of this book).
The following example shows how to generate a test class skeleton for a class named Sample.
phpunit --skeleton Sample PHPUnit 2.3.0 by Sebastian Bergmann. Wrote test class skeleton for Sample to SampleTest.php. phpunit SampleTest |

在PHP开发中,测试是非常重要的一个环节,测试可以大大减少错误的发生,提高代码质量。Mock测试是测试中的一种形式,它可以模拟出虚假的对象或数据,以便测试我们代码的某个特定功能或场景。PHPUnit是PHP中非常流行的一个测试框架,它支持Mock测试。在这篇文章中,我们将探讨如何使用PHPUnit进行Mock测试。一、什么是Mock测试在开始之前,我们先来了

PHP是一种常见的开源编程语言,广泛应用于Web开发中,它的优点就在于易学、易用、可拓展性强等优点。而作为开发者,我们为了在保证代码质量的同时提高开发效率,必不可少的就是测试和测试报告的使用。在PHP开发中,有很多测试和测试报告工具,其中最常见的就是PHPUnit。然而,PHPUnit虽然简单易用,但是需要一些编写测试用例的基础知识,如果不熟悉,使用起来还是

在现代的软件开发中,代码质量和规范是极为重要的因素。不仅可以让代码更加整洁易于维护,还可以提高代码的可读性和可扩展性。但是,如何检查代码的质量和规范呢?本文将介绍如何使用PHP和PHPUnit来实现这一目标。第一步:检查代码规范在PHP开发中,有一种非常流行的代码规范,它被称为PSR(PHP标准规范)。PSR规范的目的是使PHP代码更具可读性和可维护性。其中

在PHP项目开发中,单元测试是一项很重要的任务。PHPUnit和Mockery是两个相当流行的PHP单元测试框架,其中PHPUnit是一个被广泛使用的单元测试工具,而Mockery则是一个专注于提供统一而简洁的API以创建和管理对象Mock的对象模拟工具。通过使用PHPUnit和Mockery,开发人员可以快速高效地进行单元测试,以确保代码库的正确性和稳定性

PHP编程中有哪些常见的代码质量工具?在现代的软件开发中,代码质量是非常重要的。如果代码质量不好,不仅会降低代码的可读性,增加维护难度,还会造成安全漏洞等一系列问题。而在PHP编程中,我们可以使用一些代码质量工具来检查代码的质量。本文将介绍一些常见的PHP代码质量工具。PHP_CodeSnifferPHP_CodeSniffer是一个用于静态分析PHP代码的

检查代码质量是每个程序员都必须要做的任务,而PHP中也有很多工具可以用于检查代码的质量和风格,从而提高代码的可读性和可维护性,提高代码的可靠性和安全性。本文将介绍几种常见的PHP代码检查工具,并对它们进行简单的比较和评估,希望可以帮助读者在开发过程中选择合适的工具,提高代码质量和效率。PHP_CodeSnifferPHP_CodeSniffer是一个广泛应用

随着软件开发行业的发展,测试逐渐成为了不可或缺的一部分。而单元测试作为软件测试中最基础的一环,不仅能够提高代码质量,还能够加快开发者开发和维护代码的速度。在PHP领域,PHPUnit是一个非常流行的单元测试框架,它提供了各种功能来帮助我们编写高质量的测试用例。在本文中,我们将介绍如何使用PHPUnit进行PHP单元测试。安装PHPUnit在使用PHPUnit

PHPUnitはphpでのユニットテストを効率化するためのフレームワークです。jenkinsと組み合わせると、CI(継続的インテグレーション)プロセスにテストを組み込み、コード変更のたびにテストを実行できます。JenkinsのPHPUnitプラグインJenkinsのPHPUnitプラグインを使用すると、JenkinsジョブにPHPUnitテストを簡単に追加できます。このプラグインは、テストの実行、結果の表示、および失敗したテストの自動通知を行います。PHPUnitのインストールと構成PHPUni


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

Notepad++7.3.1
Easy-to-use and free code editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
