-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Throw TestFailedOnTimeoutException instead of plain Exception on timeout. Fixes #771 #777
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
Changes from 1 commit
dcc298c
619f4ff
b645d2b
bf2f922
6a302a6
66bfb24
9c5a2f2
26c25f3
a4f088d
f03bc79
44e2428
9bd737e
848f6b7
1e650b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.junit.internal.runners.statements; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you want to reference this class in your own code, we should probably not have it under "internal" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. Any ideas for a better package? |
||
|
||
public class TestFailedOnTimeoutException extends Exception { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please add Javadoc? |
||
|
||
private static final long serialVersionUID = 31935685163547539L; | ||
|
||
public TestFailedOnTimeoutException(String message) { | ||
super(message); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.internal.runners.statements.FailOnTimeout; | ||
import org.junit.internal.runners.statements.TestFailedOnTimeoutException; | ||
import org.junit.rules.ExpectedException; | ||
import org.junit.runners.model.Statement; | ||
|
||
|
@@ -61,6 +62,13 @@ public void throwTimeoutExceptionOnSecondCallAlthoughFirstCallThrowsException() | |
evaluateWithWaitDuration(TIMEOUT + 50); | ||
} | ||
|
||
@Test | ||
public void throwsTestFailedWithTimeoutException() | ||
throws Throwable { | ||
thrown.expect(TestFailedOnTimeoutException.class); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we update the expectations to check for the contents of the message? Perhaps a regex match for "test timed out after 5 seconds" (replacing "5" and "second" for the actual values, of course). |
||
evaluateWithWaitDuration(TIMEOUT + 50); | ||
} | ||
|
||
private void evaluateWithException(Exception exception) throws Throwable { | ||
statement.nextException = exception; | ||
statement.waitDuration = 0; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are making a custom exception, then perhaps we should pass these values into the constructor and provide methods in the exception to get these values so people don't have to parse the exception message