File tree Expand file tree Collapse file tree 2 files changed +23
-2
lines changed
main/java/org/junit/jupiter/engine/extension
test/java/org/junit/jupiter/engine/extension Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -26,9 +26,9 @@ static TimeoutDuration from(Timeout timeout) {
2626 private final TimeUnit unit ;
2727
2828 TimeoutDuration (long value , TimeUnit unit ) {
29- Preconditions .condition (value > 0 , () -> "value must be greater than 0 : " + value );
29+ Preconditions .condition (value > 0 , () -> "timeout duration must be a positive number : " + value );
3030 this .value = value ;
31- this .unit = Preconditions .notNull (unit , "unit must not be null" );
31+ this .unit = Preconditions .notNull (unit , "timeout unit must not be null" );
3232 }
3333
3434 public long getValue () {
Original file line number Diff line number Diff line change 4545import org .junit .jupiter .api .TestFactory ;
4646import org .junit .jupiter .api .Timeout ;
4747import org .junit .jupiter .engine .AbstractJupiterTestEngineTests ;
48+ import org .junit .platform .commons .PreconditionViolationException ;
4849import org .junit .platform .testkit .engine .EngineExecutionResults ;
4950import org .junit .platform .testkit .engine .Events ;
5051import org .junit .platform .testkit .engine .Execution ;
@@ -265,6 +266,17 @@ void includesClassNameIfMethodIsNotInTestClass() {
265266 "$NestedClassWithOuterSetupMethodTestCase#setUp() timed out after 10 milliseconds" );
266267 }
267268
269+ @ Test
270+ @ DisplayName ("reports illegal timeout durations" )
271+ void reportsIllegalTimeoutDurations () {
272+ EngineExecutionResults results = executeTestsForClass (IllegalTimeoutDurationTestCase .class );
273+
274+ Execution execution = findExecution (results .tests (), "testMethod()" );
275+ assertThat (execution .getTerminationInfo ().getExecutionResult ().getThrowable ().orElseThrow ()) //
276+ .isInstanceOf (PreconditionViolationException .class ) //
277+ .hasMessage ("timeout duration must be a positive number: 0" );
278+ }
279+
268280 private Execution findExecution (Events events , String displayName ) {
269281 return getOnlyElement (events //
270282 .executions () //
@@ -465,4 +477,13 @@ void testMethod() {
465477
466478 }
467479
480+ static class IllegalTimeoutDurationTestCase {
481+
482+ @ Test
483+ @ Timeout (0 )
484+ void testMethod () {
485+ }
486+
487+ }
488+
468489}
You can’t perform that action at this time.
0 commit comments