Add annotations for Unittest API
kiesel opened this issue · 0 comments
Scope of Change
The unittest API should be extended to support some of the annotation
based features that will be introduces with JUnit 4.0.
These annotations include
. @expect
. @timeout
Rationale
Sometimes one might not want to check for certain return values. Issueing
exceptions to check error handling code is even quite common.
The annotation @expect
will simplify the common case where one needs to
check that a specific exception has been thrown.
The annotation @timeout can be used to check the runtime behaviour of
a method.
Functionality
The @expect annotation takes the name of the expected exception:
<?php
#[@test, @expect('lang.IllegalArgumentException')]
function testMyFault() {
$object= &new MyExceptionThrowingClass();
$object->throwExpectedException();
}
?>
The @timeout annotation takes the amount of seconds a method may take
to execute.
<?php
#[@test, @timeout(13)]
function testTimeout() {
// Call lengthy method
lengthyMethod();
}
?>
The method will be interrupted if it didn't complete within the time
specified and the result will be assumed as failed.
Security considerations
n/a
Speed impact
Of course, exception handling is a slow thing, but this doesn't count
for unit testing.
Dependencies
- ext/pcntl for the timeout thing
http://php3.de/pcntl_alarm
Related documents
- JUnit 4 overview
http://www.beust.com/weblog/archives/000292.html - JUnit 4.0 (german)
http://www.frankwestphal.de/JUnit4.0.html - Patch against util.profiling.unittest.TestCase
http://xp-framework.net/downloads/rfc0032.diff - XP Unit testing introduction
http://xp-framework.info/xml/xp.en_US/news/view?67