xp-framework / unittest

Unittests for the XP Framework
0 stars 0 forks source link

Add possibility to fail all tests from within `@beforeClass` methods #31

Closed thekid closed 6 years ago

thekid commented 6 years ago

Exceptions from @beforeClass methods skip all tests if they fail. In certain situations, if may be better to fail them.

This can be done by throwing a PrerequisitesFailedError (instead of a PrerequisitesNotMetError) from these methods.

Example

use unittest\{TestCase, PrerequisitesFailedError};

class ExampleTest extends TestCase {

  #[@beforeClass]
  public static function startServer() {
    $server= ...;
    try {
      $server->start();
    } catch (CouldNotStartServer $e) {
      throw new PrerequisitesFailedError('Could not start server', $e, [$server]);
    }
  }

  // ...
}
thekid commented 6 years ago

Released in https://github.com/xp-framework/unittest/releases/tag/v9.6.0