Next-Gen App & Browser Testing Cloud
Trusted by 2 Mn+ QAs & Devs to accelerate their release cycles

In this blog, you will learn how to use @RepeatedTest annotation in JUnit 5 to achieve the repetition of test cases and the use case for that.
Ruchira Shukla
January 22, 2026
The JUnit framework is a popular test automation framework for unit testing in Java. The latest version of JUnit, i.e., JUnit 5 (also known as Jupiter), offers a number of improvements over JUnit 4. However, the community of JUnit users are often divided on this new release, with some favoring the stability of JUnit 4 and others preferring the new features being introduced with each release of JUnit 5. If you have been using JUnit 4, you can check the JUnit4 vs JUnit 5 comparison to understand the difference between them.
While JUnit 5 has introduced a lot of new and useful annotations, @RepeatedTest in JUnit 5 is one of the most powerful JUnit 5 annotations in the list. As an automation tester, we often get into a situation where we want to repeat a test case execution. If we have a flexible automation framework, we can pass such information through configuration in specific cases. Having said that, it is always good to have a feature that exclusively supports this requirement and can be instrumental while performing Selenium automation testing.
The @RepeatedTest annotation in JUnit 5 (JUnit Jupiter) allows developers to run the same test method multiple times to check stability, reliability, or performance under repeated execution.
What is the use of RepeatedTest?
The @RepeatedTest annotation helps ensure stability in test results when behavior might be inconsistent due to timing, environment, or randomness.
How to use @RepeatedTest annotation in JUnit 5?
Here’s how you can use the @RepeatedTest annotation step-by-step:
@RepeatedTest(n) where “n” is the number of times it should execute.@BeforeEach and @AfterEach methods run before and after every repetition, while @BeforeAll and @AfterAll run only once.How to configure the custom test display name using @RepeatedTest annotation in JUnit 5?
You can customize how each repetition appears in test reports using the name attribute with placeholders.
{displayName}, {currentRepetition}, and {totalRepetitions} for better readability.@RepeatedTest(5)
void repeatedTestExample() {
// Test logic here
}
RepeatedTest, as the name suggests, is a test that is repeated during the test execution a certain no. of times. Let’s not confuse this with the parameterized test in JUnit. A parameterized test repeatedly executes with different input data, while a repeated test repeatedly executes with the same input data.
If you are preparing for an interview you can learn more through Junit interview questions.
As a QA engineer, the first question that comes to mind is “Why do we need to repeat a test multiple times?”. First, there can be many scenarios where we need to do so. For example, a specific link on a web page results in an environment error, but this error disappears after two clicks. This is a known issue and you do not want your test case to fail for such a known issue.
Another scenario can be automating an application and clicking a link or navigating from one page to another. It always takes different load times, which sometimes results in timeout exceptions for the test case. In this case, we might want to execute the test case multiple times to get an average load time. And then pass that average load time as the threshold for the timeout.
Basically, most of the time, repetition is required when there is some randomness in the test case.
So, if you’re curious about the world of JUnit 5 annotations, this video will help you get started. You’ll learn JUnit 5 annotations in Selenium, how to write a JUnit test with Selenium, how to execute JUnit tests on a cloud Selenium Grid, and much more.
However, you can follow the TestMu AI YouTube Channel and stay updated with more such videos on the JUnit tutorial with Selenium.
JUnit Jupiter @RepeatedTest annotation is used to repeat the test case for specified no. of times. Each invocation of the test case behaves like a regular @Test method, so it has support for the same lifecycle callbacks and extensions in JUnit 5.
The following example declares myTest() to repeat execution five times:
@RepeatedTest(5)
void myTest() {
// ...
}
There are certain rules associated with the method @RepeatedTest in JUnit 5.
Let’s see how it is used in the test case with a basic example-
Test Case
package Test;
import java.net.MalformedURLException;
import java.net.URL;
import org.junit.After;
import org.junit.Before;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.RepeatedTest;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.junit.jupiter.api.Test;
import junit.framework.Assert;
public class RepeatedTestDemo {
public WebDriver driver = null;
@BeforeEach
public void setup() throws Exception {
System.setProperty("webdriver.chrome.driver",
"DRIVER_EXE_PATH");
driver = new ChromeDriver();
}
@RepeatedTest(value = 5)
public void repeatedTestDemo() throws Exception {
try {
driver.get("https://www.amazon.in/");
driver.findElement(By.xpath("//a[text()='Best Sellers']")).click();
String actual = driver.findElement(By.xpath("//div[@id='zg_banner_text']/div[1]")).getText();
Assert.assertEquals("Pass", "Amazon Bestsellers", actual);
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
@AfterEach
public void tearDown() throws Exception {
driver.quit(); // for illustration
}
}
Following is the output of the above code:

As we can see, by default, JUnit displays the repetition number along with the total number of repetitions. We can also modify the display name, which we will discuss later. For now, let us do a code walk-through.
As it is quite evident that @RepeatedTest in JUnit 5 is treated as @Test annotation by JUnit 5, the lifecycle is also the same. For example, @BeforeEach and @AfterEach methods will be invoked before and after each invocation of the @RepeatedTest method in JUnit 5.
Also Read – JUnit Asserts With Examples
@RepeatedTest in JUnit 5 supports DisplayName placeholder to give a custom display name to the test. It returns the value provided in the annotation @DisplayName for the test method. If there is no @DisplayName annotation given, it returns the method name itself.
Syntax
@RepeatedTest(name={displayName})
The annotation supports two display name patterns.
SHORT_DISPLAY_NAME is the default placeholder. When used, JUnit displays the following pattern-
repetition {currentRepetition} of {totalRepetitions}
LONG_DISPLAY_NAME when used, JUnit display the following pattern-
{displayName}:: repetition {currentRepetition} of {totalRepetitions}
Where the placeholders-
{currentRepetition}: is the current repetition count
{totalRepetitions}: is the total number of repetitions
We can also provide a string value and the supported placeholders to make it more meaningful. Let’s modify the above code to demonstrate the custom display name.
package Test;
import java.net.MalformedURLException;
import java.net.URL;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.RepeatedTest;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class RepeatedTestDemo {
public WebDriver driver = null;
@BeforeEach
public void setup() throws Exception {
System.setProperty("webdriver.chrome.driver",
"YOUR_DRIVER_EXE_PATH");
driver = new ChromeDriver();
}
@DisplayName("Link Verification")
@RepeatedTest(value = 3, name = "Testcase: {displayName} _ The current repetition count is {"{currentRepetition}"} out of Total repetition count {"{totalRepetitions}"}")
public void repeatedTestDemo() throws Exception {
try {
driver.get("https://www.amazon.in/");
driver.findElement(By.xpath("//a[text()='Best Sellers']")).click();
String actual = driver.findElement(By.xpath("//div[@id='zg_banner_text']/div[1]")).getText();
Assert.assertEquals("Pass", "Amazon Bestsellers", actual);
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
@AfterEach
public void tearDown() throws Exception {
driver.quit(); // for illustration
}
}
In the above example, the displayName is passed as a parameter, and it would replace the value of @displayName annotation at the run time. Therefore, the output of the above code would be something as shown below:


Deliver immersive digital experiences with Next-Generation Mobile Apps and Cross Browser Testing Cloud
This JUnit certification establishes testing standards for those who wish to advance their careers in Selenium automation testing with JUnit.
Here’s a short glimpse of the JUnit certification from TestMu AI:
RepetitionInfo interface defines methods to retrieve the information about the current repetition and the total no. of repetitions. Here’s how we can use it.
RepeatedTest interface defines methods to get attributes of the annotation @RepeatedTest of the test method. Here’s how we can use it-
However, the best way to harness the real potential of the JUnit framework for test automation is to shift it from a local Selenium Grid to a cloud-based Selenium Grid so that it can be executed in any browser anywhere in the world. When combined with TestMu AI, the JUnit framework allows developers to execute automated acceptance tests on a cloud Selenium Grid, which provides true remote testing capabilities.
TestMu AI is a cloud-based automated cross browser testing platform that allows you to easily run Selenium tests on more than 2,000 real browsers and operating systems in the cloud. You can run tests on any online browser or operating system with just one command, or create powerful suites that contain thousands of your own custom-built test steps.
Selenium-Jupiter allows you to run Selenium tests against a Grid of Remote Web Browsers (RWB) on different browser and platform combinations. TestMu AI helps you run parallel testing in Selenium with increased efficiency and speed, by making use of cloud-based automation.
Also Read – Parallel Testing With JUnit 5 And Selenium [Tutorial]
In this Selenium JUnit 5 tutorial, we have covered the annotation @RepeatedTest in JUnit 5 along with its use case. As we discussed, the annotation is particularly useful when we want to ascertain a scenario. In addition, the advantage of having an exclusive functionality for such a case is wonderful. So, what’s your use case for this annotation? Let us discuss this in the comments.
Happy Testing!
Did you find this page helpful?
More Related Hubs
TestMu AI forEnterprise
Get access to solutions built on Enterprise
grade security, privacy, & compliance