Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find a way to set a default global per-test timeout for Java Java unit tests #21377

Open
damccorm opened this issue Jun 4, 2022 · 5 comments

Comments

@damccorm
Copy link
Contributor

damccorm commented Jun 4, 2022

Apparently java unit tests don't have timeouts. And as far as I can tell, Junit lets you set timeouts for individual tests and test classes, but provides no easy way to set a global timeout across multiple classes.

Imported from Jira BEAM-13523. Original Jira may contain additional context.
Reported by: ibzib.

@gpt3ch
Copy link

gpt3ch commented Jun 5, 2022

Hello @damccorm , I started looking at this issue. After reading more about this, a way to implement a global timeouts for the unit tests is to create a base test class and specify a Timeout rule in it, then make all the test classes inherit the base test class, this will make all the test cases timeout if they cross the threshold without having to specify @timeout annotation over each test method. Is this an acceptable solution?

@damccorm
Copy link
Contributor Author

damccorm commented Jun 5, 2022

Hey @gpt3ch! That definitely seems reasonable to me, but I also don't have a ton of context on the Java test suites (I just migrated the issue to GitHub, this was originally reported by @ibzib).

Tagging a few folks who might have more context here in case they have thoughts: @ibzib, @klk, @kileys, or @y1chi

@damccorm damccorm added tests and removed testing labels Jun 16, 2022
@sulthan309
Copy link

Hello @damccorm, 'Global declarative Timeout' feature is implemented in Junit from Junit 5.5 version where we can set the global timeout for all the TCs.
Documentation : https://junit.org/junit5/docs/5.5.0/user-guide/index.html#writing-tests-declarative-timeouts (section 2.19.2. Default Timeouts)

@Ashutosh2512
Copy link

Hi @damccorm,

Is the issue still relevant or the solution provided by @sulthan309 is acceptable, given it is an experimental feature from JUnit ? If it is relevant, I would like to pick it up.

@damccorm
Copy link
Contributor Author

damccorm commented Oct 4, 2024

I think it is still relevant since as far as I know nobody went and actually added the timeouts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants