Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to add a tag named "fast" to the test method.
JUnit
@Test @Tag("[1]") void testQuick() { // test code here }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a tag name that does not match the test purpose.
Forgetting to put the tag name inside quotes.
✗ Incorrect
The @Tag annotation is used to categorize tests. Here, "fast" is the correct tag to mark the test as fast.
2fill in blank
mediumComplete the code to add a tag named "database" to the test class.
JUnit
@Tag("[1]") public class DatabaseTests { @Test void testConnection() { // test code } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Placing the tag annotation on the method instead of the class.
Using an unrelated tag name.
✗ Incorrect
The @Tag annotation on the class applies the tag "database" to all tests inside the class.
3fill in blank
hardFix the error in the tag annotation to correctly tag the test as "integration".
JUnit
@Test
@Tag([1])
void testIntegration() {
// test code
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the tag name without quotes causes a syntax error.
Using single quotes instead of double quotes.
✗ Incorrect
The tag name must be a string literal in quotes. So "integration" is correct.
4fill in blank
hardFill both blanks to tag the test method with "slow" and "ui" tags.
JUnit
@Test
@Tags({@Tag("[1]"), @Tag("[2]")})
void testUI() {
// test code
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Tag multiple times without @Tags wrapper.
Mixing tag names or missing quotes.
✗ Incorrect
Use @Tags with multiple @Tag annotations to add several tags. Here, "slow" and "ui" are correct.
5fill in blank
hardFill all three blanks to tag the test class with "performance", "database", and "critical" tags.
JUnit
@Tags({@Tag("[1]"), @Tag("[2]"), @Tag("[3]")})
public class PerformanceTests {
@Test
void testLoad() {
// test code
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to use @Tags wrapper for multiple tags.
Using incorrect tag names or missing quotes.
✗ Incorrect
Use @Tags with multiple @Tag annotations to add all three tags to the class.