Recall & Review
beginner
What is the purpose of the
@Tag annotation in JUnit?The
@Tag annotation is used to categorize tests in JUnit. It helps group tests so you can run or exclude specific categories easily.Click to reveal answer
intermediate
How do you apply multiple tags to a single test method in JUnit?
You apply multiple
@Tag annotations by adding them above the test method, each with a different tag name. For example:<br>@Tag("fast")<br>@Tag("database")<br>void testMethod() { ... }Click to reveal answer
beginner
True or False:
@Tag annotations can be used on test classes as well as test methods.True. You can put <code>@Tag</code> on a test class to tag all tests inside it, or on individual test methods for more specific categorization.Click to reveal answer
intermediate
How can you run only tests with a specific tag using JUnit?
You configure your test runner or build tool (like Maven or Gradle) to include only tests with a specific
@Tag. For example, in Maven Surefire plugin, you can specify -Dgroups=fast to run tests tagged with @Tag("fast").Click to reveal answer
beginner
What is a practical example of using
@Tag in a real project?You might tag tests as
@Tag("integration") for slow tests that hit a database, and @Tag("unit") for fast, isolated tests. This way, you can run only unit tests during development for speed, and run integration tests separately.Click to reveal answer
What does the
@Tag annotation do in JUnit?✗ Incorrect
@Tag is used to group tests so you can run or exclude them by category.Can you apply multiple
@Tag annotations to a single test method?✗ Incorrect
JUnit allows multiple
@Tag annotations on the same method to assign multiple categories.Where can
@Tag annotations be placed?✗ Incorrect
@Tag can be used on classes to tag all tests inside, or on individual methods.How do you run tests with a specific tag using Maven?
✗ Incorrect
Maven Surefire plugin uses
-Dgroups=tagName to run tests with that tag.Why is tagging tests useful in a project?
✗ Incorrect
Tagging helps run only needed tests, saving time during development or CI.
Explain how you would use
@Tag annotations to organize tests in a JUnit project.Think about grouping tests for easier execution control.
You got /4 concepts.
Describe the steps to run only tests with a specific tag using a build tool like Maven.
Focus on how tagging connects with test execution commands.
You got /4 concepts.