Stop Tests after Period of Time

We have an internal tool that runs integration tests based on changes made to the source code. Would it be possible to place a maximum time limit so that the test task stops after that amount of time elapses?

By default, a task will never time out, but you can set a timeout value on any task.

For example, if your integration test task was the standard test task in the project and you wanted to stop after 15 minutes:

test {
    timeout = Duration.ofMinutes(15)

As far as I can tell, if I use this to stop my tests before the task is done, I don’t get anything published to xml or html files… :frowning: … Am I missing something?

That’s what would be expected. If you’re configuring a Gradle task timeout, the entire task will be terminated when the timeout is reached. Gradle can’t tell your testing framework it should stop running some things while continuing others. It’s a hard kill.

It sounds like you would be better served by configuring timeouts in your test framework so that some tests abort if they take too long, which involves your test framework, and not Gradle at all.

1 Like