![]() |
JUnit 5 encourages a modular approach to test creation with its test suites. These suites function as containers, bundling multiple test classes for easier management and collective execution within a single run. In this article, we will learn about JUnit 5 – Test Suites. Test SuiteIn JUnit 5, a test suite is a way to combine multiple test classes and run them together as a single unit. The @Suite annotation on the test class is used to define a test suite. You can also include specific test classes in the suite using annotations like @SelectClasses, @SelectPackages, or @SelectClasspathRoots, that help to filter out the test classes you want to run together. Now we go through an example, to execute a test suite. Example of JUnit 5 – Test SuitesHere we take a Java program that has methods add() and subtract() to perform addition and subtraction of two numbers. We have written test classes for both methods separately as AdditionTest and SubtractionTest. Now we can run both of them collectively as a single unit, under a test suite CalculatorTestSuite which is annotated by @Suite, and then @SelectClasses which includes both our test classes. Calculator.java File:Java
AdditionTest.java File:Java
SubtractionTest.java File:Java
CalculatorTestSuite.java File:Java
Output:![]() Output |
Reffered: https://www.geeksforgeeks.org
Advance Java |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 9 |