A test suite is used to group together and run a number of unit test cases. To run the suite tests in JUnit, both the @RunWith
and @Suite
annotations are used.
@RunWith
has been replaced with @ExtendWith
annotation, but it is still used for backward compatibility.
When a class annotated @RunWith(Suite.class)
is run, the SuiteClasses
annotation specifies which classes should be run.
With the above annotations, the suite's test classes will begin executing one by one.
Below are the steps to create test suites and test runner.
Step 1: First, create a simple test class; for example, DemoTest
and annotate a method with @test
.
Step 2: Create a new test class; for example, DemoTest1
and a method annotated with @test
.
Step 3: To create a testSuite
, annotate the class with @RunWith(Suite.class)
and @SuiteClasses(class1.class2.....)
first.
Step 4: To run our test suite, create a Test Runner class.
JUnit test suite increases developer and tester productivity by allowing them to test multiple application scenarios in a single shot rather than testing them individually.
Free Resources