0
0
JUnittesting~5 mins

Test suites with @Suite in JUnit - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of using @Suite in JUnit?
The @Suite annotation groups multiple test classes to run them together as one test suite, making it easier to organize and execute related tests.
Click to reveal answer
beginner
How do you specify which test classes belong to a test suite using @Suite?
You use the @Suite.SuiteClasses annotation with an array of test class names inside the test suite class.
Click to reveal answer
beginner
Write a simple example of a JUnit test suite using @Suite.
import org.junit.runner.RunWith;
import org.junit.runners.Suite;

@RunWith(Suite.class)
@Suite.SuiteClasses({TestClass1.class, TestClass2.class})
public class MyTestSuite {
}
 This runs TestClass1 and TestClass2 together.
Click to reveal answer
beginner
What annotation must be used on a class to make it a test suite in JUnit?
The class must be annotated with @RunWith(Suite.class) to tell JUnit to run it as a suite.
Click to reveal answer
beginner
Can a test suite class contain test methods?
No, a test suite class only groups other test classes and does not contain test methods itself.
Click to reveal answer
Which annotation is used to specify the classes included in a JUnit test suite?
A@Suite.SuiteClasses
B@TestClasses
C@RunWithClasses
D@IncludeTests
What annotation must be placed on a class to run it as a JUnit test suite?
A@TestSuite
B@SuiteRunner
C@RunWith(Suite.class)
D@RunSuite
Can a JUnit test suite class contain test methods?
AYes, it can contain test methods.
BOnly if it extends a test class.
COnly if annotated with @Test.
DNo, it only groups test classes.
What is the main benefit of using a test suite with @Suite in JUnit?
ATo run multiple test classes together easily.
BTo write fewer test methods.
CTo automatically generate test reports.
DTo skip tests during execution.
Which import is necessary to use @Suite in JUnit 4?
Aimport org.junit.suite.Suite;
Bimport org.junit.runners.Suite;
Cimport org.junit.runner.Suite;
Dimport org.junit.suites.Suite;
Explain how to create a test suite in JUnit using @Suite and what annotations are required.
Think about how you tell JUnit to run multiple classes together.
You got /3 concepts.
    Describe the benefits of grouping tests into a suite with @Suite in JUnit.
    Consider how running tests together helps in real projects.
    You got /3 concepts.