Package rife.bld.extension.testing
Class CouldFailExtension
java.lang.Object
rife.bld.extension.testing.CouldFailExtension
- All Implemented Interfaces:
Extension,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
- Test executes normally
- If test passes, extension does nothing
- If test fails,
handleTestExecutionExceptionis called:- Extension checks for
@CouldFailon method, then class - If annotation not found, the test fails normally
- If
withExceptionsis empty, accept any exception - If
withExceptionsis specified, check if thrown exception matches - If the exception is accepted: throw
TestAbortedException - If the exception is not accepted: re-throw the original exception
- Extension checks for
Exception Matching
An exception is considered "accepted" if:
withExceptionsis 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:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidhandleTestExecutionException(ExtensionContext context, Throwable throwable)
-
Constructor Details
-
CouldFailExtension
public CouldFailExtension()
-
-
Method Details
-
handleTestExecutionException
public void handleTestExecutionException(ExtensionContext context, Throwable throwable) throws Throwable - Specified by:
handleTestExecutionExceptionin interfaceTestExecutionExceptionHandler- Throws:
Throwable
-