From the course: Java: Testing with JUnit
Unlock the full course today
Join today to access over 24,700 courses taught by industry experts.
Timeouts
- [Instructor] It is not uncommon that you want to specify a certain max execution time for a test. With different and older JUnit dependencies, there were multiple ways to do this. We could add timeout as an attribute to do the test and we could create a rule for all the tests in our class. Right now, there's more a elegant solution, and we're going to see two solutions actually. We're going to see the @Timeout annotation and the assertTimeout methods. I have prepared a class here that I will use to demonstrate how to use timeout in JUnit 5. So the first one is to have @Timeout on top of your Test class. And we can just say @Timeout here, and then it will take two attributes: the amount that it can wait and then the unit. So I'm going to say value and this is going to be 500. And then the time unit, which is going to be milliseconds. I wonder if that would be a bit long test. So let's go for the milliseconds.…
Contents
-
-
-
-
-
(Locked)
Dependency injection in your tests5m 7s
-
Repeated tests2m 55s
-
(Locked)
Parameterized tests9m 29s
-
(Locked)
Timeouts4m 49s
-
(Locked)
Parallel execution3m 42s
-
(Locked)
Lifecyle control: Before and after5m 10s
-
(Locked)
Custom messages and reports4m 28s
-
(Locked)
Conditional test execution4m 19s
-
(Locked)
Disabling unit tests1m 45s
-
(Locked)
Solution: Refactoring1m 1s
-
(Locked)
-
-