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

Feature request: add java.time.Duration support to org.junit.rules.Timeout #1619

Open
kluever opened this issue Jun 19, 2019 · 7 comments
Open

Comments

@kluever
Copy link
Contributor

kluever commented Jun 19, 2019

Representing durations as longs can easily lead to unit mismatch problems.
Representing durations as long, TimeUnit pairs can require plumbing 2 values through multiple layers (and can suffer from unit mismatch or truncation issues).

Could proper java.time.Duration support be added to the Timeout class?

(If this should be filed under junit5, please let me know and I'll open it there.)

@marcphilipp
Copy link
Member

JUnit Jupiter is about to add support for "declarative" timeouts using a @Timeout annotation on test classes or methods (see User Guide for details). It also uses the long, TimeUnit combination because Durations cannot be expressed in annotations. In addition, it allows to declare timeouts globally, i.e. to be applied for all tests, using a configuration parameter (which can be specified using a properties file or a system property) in a custom format, e.g. 5 s.

@kluever How do you currently do the plumbing to pass the duration through multiple layers?

@carl-mastrangelo
Copy link

@marcphilipp does that work with DisableOnDebug ?

@Tibor17
Copy link
Contributor

Tibor17 commented Jun 20, 2019

In the API architecture perspective this is caled value object. That means both values long and TimeUnit cannot be safely decouled. Using java.time.Duration makes sense to me as this is the wrapper and good value object in this JUnit 4.

@Tibor17
Copy link
Contributor

Tibor17 commented Jun 20, 2019

@marcphilipp
Not in JUnit5 but in yes JUnit4 because org.junit.rules.Timeout is not annotation. So this can be nice here.

@kluever
Copy link
Contributor Author

kluever commented Jun 20, 2019

Re: "How do you currently do the plumbing to pass the duration through multiple layers?"

I'm not sure I fully understand the question, but in order to use a long, TimeUnit pair, you need to pass both variables through all layers of your application. With Duration, you only need to pass 1 variable.

@marcphilipp
Copy link
Member

How do you call JUnit so that there are layers around it?

@marcphilipp
Copy link
Member

JUnit 4 is compatible with Java 5 and will stay that way. Thus, adding support for Duration would be rather involved, if feasible at all.

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

No branches or pull requests

4 participants