-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Document that Assumptions cannot abort a failed test #4084
Comments
@AfterEach
@AfterEach
That's by design. It is impossible to abort a test that has already failed. JUnit uses a
So, this is in fact documented at the "platform level", but this is not clearly documented in the Javadoc or User Guide regarding In light of that, I have changed this to a |
@er2 Here's a way to accomplish what you're looking for: import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assumptions.abort;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.api.extension.TestExecutionExceptionHandler;
public class GetByAgeTest {
LocalDateTime NOW = LocalDateTime.now().truncatedTo(ChronoUnit.SECONDS);
@RegisterExtension
TestExecutionExceptionHandler exceptionHandler = (context, throwable) -> {
boolean timeDidntIncrementDuringTestRun = NOW.equals(LocalDateTime.now().truncatedTo(ChronoUnit.SECONDS));
if (timeDidntIncrementDuringTestRun) {
throw throwable;
} else {
abort();
}
};
@Test
public void fast() {
fail();
}
@Test
void slow() throws InterruptedException {
Thread.sleep(1_500);
fail();
}
} |
Steps to reproduce
Expected Behavior: Test Ignored
Actual Behavior: Test Failed
Context
What I'm trying to do
The text was updated successfully, but these errors were encountered: