Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add annotations for Unittest API #32

Closed
kiesel opened this issue Oct 17, 2011 · 0 comments
Closed

Add annotations for Unittest API #32

kiesel opened this issue Oct 17, 2011 · 0 comments

Comments

@kiesel
Copy link
Member

kiesel commented Oct 17, 2011

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant