Annotation Interface CouldFail


JUnit annotation to mark a test as allowed to fail.

When a test annotated with @CouldFail fails, the failure is accepted and the test is aborted (shown as skipped). If the test passes, it continues to pass normally.

This is similar to JUnit Pioneer's @ExpectedToFail but with inverted logic: a passing test continues to pass (not fail), making it suitable for acknowledging known issues without expecting them to be fixed.

Usage

Accept Any Failure


 @Test
 @CouldFail
 void testFlakeyOperation() {
     // Test that might fail - any exception will be accepted
 }
 

Accept Specific Exceptions


 @Test
 @CouldFail(withExceptions = UnsupportedOperationException.class)
 void testUnimplementedFeature() {
     // Only UnsupportedOperationException will be accepted
     // Other exceptions will fail the test normally
 }
 

Accept Multiple Exception Types


 @Test
 @CouldFail(withExceptions = {IOException.class, TimeoutException.class})
 void testNetworkOperation() {
     // IOException or TimeoutException will be accepted
     // Other exceptions will fail the test normally
 }
 

When to Use

  • Known bugs or issues that haven't been fixed yet
  • Intermittent failures in CI/CD pipelines
  • Platform-specific issues
  • External service dependencies that may be unavailable
  • Unimplemented features (stub code throwing UnsupportedOperationException)

Behavior

  • If the test passes: continues to pass (no special handling)
  • If the test fails with accepted exception: test is aborted (shown as skipped)
  • If the test fails with non-accepted exception: test fails normally
Since:
1.0
See Also:
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Class<? extends Throwable>[]
    Specific exception types that will be accepted as failures.
  • Element Details

    • withExceptions

      Class<? extends Throwable>[] withExceptions
      Specific exception types that will be accepted as failures.

      If empty (default), any exception will be accepted. If specified, only these exception types (and their subclasses) will be accepted. Any other exception will cause the test to fail normally.

      Returns:
      array of exception classes to accept
      Default:
      {}