Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering Software Testing with JUnit 5

You're reading from   Mastering Software Testing with JUnit 5 Comprehensive guide to develop high quality Java applications

Arrow left icon
Product type Paperback
Published in Oct 2017
Publisher Packt
ISBN-13 9781787285736
Length 350 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Boni Garcia Boni Garcia
Author Profile Icon Boni Garcia
Boni Garcia
Arrow right icon
View More author details
Toc

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, we will see that trace five times:

Execution of repeated test in the console

In addition to specifying the number...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime