课程: Complete Guide To Java Testing with JUnit 5 & Mockito
今天就学习课程吧!
今天就开通帐号,24,600 门业界名师课程任您挑!
Timeout
- [Instructor] Introduced in Junit 5, the Timeout annotation is a great tool for controlling the execution time of tests. This annotation allows developers to specify a maximum time limit for the execution of a test method. If the test method exceeds this specified timeout duration, it is considered a failure. This prevents tests from hanging indefinitely, and facilitates timely feedback during test execution. Let's use it in a code example. With this sample code, we want to verify a given operation is completed within five seconds. We can do this by adding a timeout annotation, @Timeout5. In between the parentheses, we add the number of seconds for the desired timeout duration. Here, it's five seconds. Let's run the test. And it looks like the test fails. This happens because the method's execution actually takes six seconds. The thread sleeps for 6,000 milliseconds or six seconds. Let's change this to 4,000 milliseconds and see if the test passes. We'll run it again. With a shorter…
内容
-
-
-
-
-
-
-
(已锁定)
Add a display name to your tests1 分钟 30 秒
-
(已锁定)
Nested tests3 分钟 31 秒
-
(已锁定)
Timeout1 分钟 47 秒
-
(已锁定)
AssertTimeout2 分钟 31 秒
-
(已锁定)
AssertAll3 分钟 50 秒
-
(已锁定)
Message suppliers2 分钟 3 秒
-
(已锁定)
Assumptions API2 分钟 57 秒
-
(已锁定)
TempDir7 分钟 15 秒
-
(已锁定)
Migrate from JUnit 4 to JUnit 52 分钟 52 秒
-
(已锁定)
Challenge: Sorting algorithm validation55 秒
-
(已锁定)
Solution: Sorting algorithm validation6 分钟 47 秒
-
(已锁定)
-
-
-
-