| Prev | Next |
PHPUnit supports the logging of test results in several formats.
The XML format supported by PHPUnit is loosely based upon the one
used by the
JUnit task for Apache Ant. The following example shows the XML
logfile generated for the tests in ArrayTest:
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="ArrayTest"
file="/home/sb/ArrayTest.php"
tests="2"
failures="0"
errors="0"
time="0.016030">
<testcase name="testNewArrayIsEmpty"
class="ArrayTest"
file="/home/sb/ArrayTest.php"
line="6"
time="0.008044"/>
<testcase name="testArrayContainsAnElement"
class="ArrayTest"
file="/home/sb/ArrayTest.php"
line="15"
time="0.007986"/>
</testsuite>
</testsuites>
The following XML logfile was generated for two tests,
testFailure and testError,
of a test-case class named FailureErrorTest and
shows how failures and errors are denoted.
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="FailureErrorTest"
file="/home/sb/FailureErrorTest.php"
tests="2"
failures="1"
errors="1"
time="0.019744">
<testcase name="testFailure"
class="FailureErrorTest"
file="/home/sb/FailureErrorTest.php"
line="6"
time="0.011456">
<failure type="PHPUnit_Framework_ExpectationFailedException">
testFailure(FailureErrorTest)
Failed asserting that <integer:2> matches expected value <integer:1>.
/home/sb/FailureErrorTest.php:8
</failure>
</testcase>
<testcase name="testError"
class="FailureErrorTest"
file="/home/sb/FailureErrorTest.php"
line="11"
time="0.008288">
<error type="Exception">testError(FailureErrorTest)
Exception:
/home/sb/FailureErrorTest.php:13
</error>
</testcase>
</testsuite>
</testsuites>
The JavaScript Object Notation (JSON)
is a lightweight data-interchange format. The following example shows
the JSON messages generated for the tests in ArrayTest:
{"event":"suiteStart","suite":"ArrayTest","tests":2}
{"event":"test","suite":"ArrayTest",
"test":"testNewArrayIsEmpty(ArrayTest)","status":"pass",
"time":0.000460147858,"trace":[],"message":""}
{"event":"test","suite":"ArrayTest",
"test":"testArrayContainsAnElement(ArrayTest)","status":"pass",
"time":0.000422954559,"trace":[],"message":""}
The following JSON messages were generated for two tests,
testFailure and testError,
of a test-case class named FailureErrorTest and
show how failures and errors are denoted.
{"event":"suiteStart","suite":"FailureErrorTest","tests":2}
{"event":"test","suite":"FailureErrorTest",
"test":"testFailure(FailureErrorTest)","status":"fail",
"time":0.000483989716,"trace":[],"message":""}
{"event":"test","suite":"FailureErrorTest",
"test":"testError(FailureErrorTest)","status":"error",
"time":0.000466108322,"trace":[],"message":""}
The Test Anything Protocol (TAP)
is Perl's simple text-based interface between testing modules. The
following example shows the TAP logfile generated for the tests in
ArrayTest:
# TestSuite "ArrayTest" started. ok 1 - testNewArrayIsEmpty(ArrayTest) ok 2 - testArrayContainsAnElement(ArrayTest) # TestSuite "ArrayTest" ended. 1..2
The following TAP logfile was generated for two tests,
testFailure and testError,
of a test-case class named FailureErrorTest and
shows how failures and errors are denoted.
# TestSuite "FailureErrorTest" started. not ok 1 - Failure: testFailure(FailureErrorTest) not ok 2 - Error: testError(FailureErrorTest) # TestSuite "FailureErrorTest" ended. 1..2
PHPUnit can generate a description of the test result as a graph that can be rendered to diagrams in several useful formats such as images using the GraphViz tools.
phpunit --log-graphviz ArrayTest.dot ArrayTest
PHPUnit 3.0.0 by Sebastian Bergmann.
..
Time: 00:00
OK (2 tests)
The following example shows the GraphViz markup generated (and saved
to the ArrayTest.dot file in the current directory)
for the tests in ArrayTest:
digraph G {
graph [ overlap="scale", splines="true", sep=".1", fontsize="8" ];
"ArrayTest" [ color="green" ];
subgraph "cluster_ArrayTest" {
label="";
"testNewArrayIsEmpty" [ color="green" ];
"testArrayContainsAnElement" [ color="green" ];
}
"ArrayTest" -> "testNewArrayIsEmpty";
"ArrayTest" -> "testArrayContainsAnElement";
}
We can now use the dot command-line tool that is
part of the GraphViz software suite to generate a graphic from this
markup:
dot -T png -o ArrayTest.png ArrayTest.dotFigure 15.1 shows the graph representation of the test result rendered from the GraphViz markup above.
Successful tests are displayed with a green border, failures and errors with a red border, and incomplete or skipped tests with a yellow border. A parent node, such as test suite, is displayed with a non-green border if it has a child node, such as a test, that was not successful.
| Prev | Next |
Copyright © 2005-2010 Sebastian Bergmann.