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

junit4->5: rewrite @Rule Timeout to @Timeout #448

Open
vlsi opened this issue Jan 2, 2024 · 1 comment
Open

junit4->5: rewrite @Rule Timeout to @Timeout #448

vlsi opened this issue Jan 2, 2024 · 1 comment
Labels
recipe Recipe request

Comments

@vlsi
Copy link

vlsi commented Jan 2, 2024

Describe the solution you'd like

JUnit 4:

import org.junit.rules.Timeout;

  @Rule
  public Timeout timeout = new Timeout(30, TimeUnit.SECONDS);

JUnit 5:

import org.junit.jupiter.api.Timeout;

  @Timeout(value = 30)
@vlsi vlsi added the enhancement New feature or request label Jan 2, 2024
@timtebeek timtebeek added recipe Recipe request and removed enhancement New feature or request labels Jan 2, 2024
@timtebeek
Copy link
Contributor

Good suggestion; we already have handling for timeouts when the timeout is specified on the @Test annotation, as seen in

@Test
void annotationWithTimeout() {
//language=java
rewriteRun(
java(
"""
import org.junit.Test;
public class MyTest {
@Test(timeout = 500)
public void test() {
}
}
""",
"""
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
public class MyTest {
@Test
@Timeout(500)
public void test() {
}
}
"""
)
);
}

We indeed lack support when a Timeout Rule is used; that can be added similar to some of the other @Rules we already handle, like ExpectedExceptionToAssertThrows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
recipe Recipe request
Projects
Status: Recipes Wanted
Development

No branches or pull requests

2 participants