Class CouldFailExtension

java.lang.Object
rife.bld.extension.testing.CouldFailExtension
All Implemented Interfaces:
Extension, TestExecutionExceptionHandler

public class CouldFailExtension extends Object implements TestExecutionExceptionHandler
JUnit extension that implements the CouldFail annotation.

This extension is automatically applied when CouldFail is present, via @ExtendWith(CouldFailExtension.class) declared on that annotation.

Execution Flow

  1. Test executes normally
  2. If test passes, extension does nothing
  3. If test fails, handleTestExecutionException is called:
    1. Extension checks for @CouldFail on method, then class
    2. If annotation not found, the test fails normally
    3. If withExceptions is empty, accept any exception
    4. If withExceptions is specified, check if thrown exception matches
    5. If the exception is accepted: throw TestAbortedException
    6. If the exception is not accepted: re-throw the original exception

Exception Matching

An exception is considered "accepted" if:

  • withExceptions is empty (accepts any exception), OR
  • The thrown exception, or any exception in its cause chain, is an instance of any class in withExceptions

Logging

When a failure is accepted, an INFO-level log message is generated:

 Test failure accepted by @CouldFail (Original exception: IOException: Connection timeout)
 

The full stack trace of the original failure is logged at FINE level for debugging.

Since:
1.0
See Also: