-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #823 from askoog/timedoutexception
Throw TestFailedOnTimeoutException instead of plain Exception on timeout. Fixes #771
- Loading branch information
Showing
5 changed files
with
73 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/org/junit/runners/model/TestTimedOutException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.junit.runners.model; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* Exception thrown when a test fails on timeout. | ||
* | ||
* @since 4.12 | ||
* | ||
*/ | ||
public class TestTimedOutException extends Exception { | ||
|
||
private static final long serialVersionUID = 31935685163547539L; | ||
|
||
private final TimeUnit fTimeUnit; | ||
private final long fTimeout; | ||
|
||
/** | ||
* Creates exception with a standard message "test timed out after [timeout] [timeUnit]" | ||
* | ||
* @param timeout the amount of time passed before the test was interrupted | ||
* @param timeUnit the time unit for the timeout value | ||
*/ | ||
public TestTimedOutException(long timeout, TimeUnit timeUnit) { | ||
super(String.format("test timed out after %d %s", | ||
timeout, timeUnit.name().toLowerCase())); | ||
fTimeUnit = timeUnit; | ||
fTimeout = timeout; | ||
} | ||
|
||
/** | ||
* Gets the time passed before the test was interrupted | ||
*/ | ||
public long getTimeout() { | ||
return fTimeout; | ||
} | ||
|
||
/** | ||
* Gets the time unit for the timeout value | ||
*/ | ||
public TimeUnit getTimeUnit() { | ||
return fTimeUnit; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters