xp-framework/rfc

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

Related documents