I would like to set a timeout for Spring integration test.
For example this basic test hangs on my side:
@SpringBootTest
public class MainTest {
@Test
@Timeout(value = 10)
void contextLoads() {
}
}
It hangs, because I have JMS client which cannot initialize connection and waits forever.
Obviously one approach is to change the JMS client, so I set it some timeout during the connection.
But I would like to have more generic approach – to be able so set timeout on tests, so if for some reason they do not complete within specific timeframe they fail.
Obviosly in the test above I tried to use the @Timeout
annotation (from Junit), but it didn’t work.
In my gradle configs I have:
test {
useJUnitPlatform()
}
For some reason I cannot find such information in internet and cannot find related topics/question. Maybe I am missing something super basic.
So can you advice me how to achieve having timeout per test in Spring? I am looking for something integrated (as this sounds super basic functionality for me) which close contexts, etc and I don’t want something super complicated hand made thing. Maybe it will be even more useful, if it can do thread dump in case of timeout, but that’s a bonus for now.
The version I am using is 2.7.18 of spring boot (this) and soon we will migrate to latest 3+ version.
Thanks in advance for your attention!