0
0
JUnittesting~10 mins

Test suites with @Suite in JUnit - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a test suite class using @Suite annotation.

JUnit
import org.junit.platform.suite.api.Suite;
import org.junit.platform.suite.api.SelectClasses;

@Suite
@SelectClasses({TestClass1.class, TestClass2.class})
public class [1] {
}
Drag options to blanks, or click blank then click option'
ATestSuiteClass
BMyTestSuite
CSuiteRunner
DTestRunner
Attempts:
3 left
💡 Hint
Common Mistakes
Using invalid class names or Java keywords.
Omitting the class declaration.
2fill in blank
medium

Complete the code to import the correct package for @Suite annotation.

JUnit
import [1];

@Suite
public class MyTestSuite {
}
Drag options to blanks, or click blank then click option'
Aorg.junit.platform.suite.api.Suite
Borg.junit.Test
Corg.junit.jupiter.api.Test
Dorg.junit.runner.RunWith
Attempts:
3 left
💡 Hint
Common Mistakes
Importing JUnit 4 annotations instead of JUnit 5.
Confusing @Suite with @RunWith.
3fill in blank
hard

Fix the error in the test suite declaration by completing the missing annotation.

JUnit
import org.junit.platform.suite.api.Suite;
import org.junit.platform.suite.api.SelectClasses;

@Suite
[1]
public class MyTestSuite {
}
Drag options to blanks, or click blank then click option'
A@RunWith(Suite.class)
B@SelectPackages("com.example.tests")
C@SelectClasses({TestClass1.class, TestClass2.class})
D@Test
Attempts:
3 left
💡 Hint
Common Mistakes
Using @RunWith which is from JUnit 4.
Using @Test which is for test methods, not suites.
4fill in blank
hard

Fill both blanks to create a test suite that selects all tests in a package.

JUnit
import org.junit.platform.suite.api.Suite;
import org.junit.platform.suite.api.[1];

@Suite
@[2]("com.example.tests")
public class PackageTestSuite {
}
Drag options to blanks, or click blank then click option'
ASelectPackages
BSelectClasses
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing @SelectClasses with @SelectPackages.
Importing the wrong annotation.
5fill in blank
hard

Fill both blanks to create a suite that selects specific classes and tags.

JUnit
import org.junit.platform.suite.api.Suite;
import org.junit.platform.suite.api.SelectClasses;
import org.junit.platform.suite.api.[1];

@Suite
@SelectClasses({TestA.class, TestB.class})
@[2]({"fast", "unit"})
public class TaggedTestSuite {
    // Suite runs only tests with specified tags
    // and classes
}
Drag options to blanks, or click blank then click option'
AIncludeTags
BExcludeTags
Attempts:
3 left
💡 Hint
Common Mistakes
Using ExcludeTags instead of IncludeTags.
Mismatching import and annotation names.