O'Reilly logo

Mastering Software Testing with JUnit 5 by Boni García

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Repeated tests

JUnit Jupiter provides for the ability to repeat a test a specified number of times simply by annotating a method with @RepeatedTest, specifying the total number of repetitions desired. Each repeated test behaves exactly as a regular @Test method. Moreover, each repeated test preserves the same lifecycle callbacks (@BeforeEach, @AfterEach, and so on).

The following Java class contains a test that is going to be repeated five times:

package io.github.bonigarcia;import org.junit.jupiter.api.RepeatedTest;class SimpleRepeatedTest {    @RepeatedTest(5)    void test() {        System.out.println("Repeated test");    }}

Due to the fact that this test only writes a line (Repeated test) in the standard output, when executing this test in the console, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required